Sample sizes

Table sample number by species and treatment

Species Treatment N
I. purpurea Alone 27
I. purpurea Competition 78
I. hederacea Competition 78

Table number of maternal line per species

Species Number of ML
I. purpurea 10
I. hederacea 5

Load Libraries

library(phyloseq)
library(ggplot2)
library(ape)
library(vegan)
library(plyr)
library(dplyr)
library(scales)
library(grid)
library(reshape2)
library(DESeq2)
library(pegas)
library(pgirmess)
library(multcomp)
library(multcompView)
library(ggpubr)
library(ggcorrplot)
library(RColorBrewer)
library(plotly)
library(ggthemes)
library(corrplot)
library(Hmisc)
library(emmeans)
library(lmerTest)


source("~/Google Drive File Stream/My Drive/IDM_Experiments-master/miSeq.R")

# Aesthetics
Tx<-theme(axis.text.y = element_text(size=20),
          axis.title.y = element_text(size=20))+
          theme(axis.text.x = element_text(vjust = 1, hjust=1,angle=0,size=20),
          axis.title.x = element_text(angle=0,size=20),
          plot.title=element_text(size=25,hjust=0))

# Margins
Margin<-theme(
  panel.background = element_rect(fill = "white"),
  plot.margin = margin(2, 2, 2, 2, "cm"),
  plot.background = element_rect(
    fill = "white",
    colour = "black",
    size = 1
  )
)

# Aesthetics
Tx2<-theme(axis.text.y = element_text(size=20),
          axis.title.y = element_text(size=25))+
          theme(axis.text.x = element_text(vjust = 1, hjust=1,size=25),
          axis.title.x = element_text(size=25),
          plot.title=element_text(size=25,hjust=0))

GoldGrey=c("#F1CE63","#79706E")
GreenBlue=c("#59A14F","#4E79A7")

Sequence data analysis

### loading mothur output with FWDB+silva taxonomy and sample metadata. 
### Experiments run in 

# Read in mothur output (NOTE you can download mothur output data HERE: https://drive.google.com/drive/folders/1u_KjbdsIcwLEA_Yh4MCYrexvj0YWQrxb?usp=sharing)

setwd("/Volumes/GoogleDrive/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Subset_Mothur_Output/")

sharedfile <- "stability.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.opti_mcc.shared"
taxfile <- "stability.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.opti_mcc.0.03.cons.taxonomy"

mothurdata <- import_mothur(mothur_shared_file = sharedfile,mothur_constaxonomy_file = taxfile)


setwd("/Volumes/GoogleDrive/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output")

sampledata= read.csv('MetaDataTest.csv')

SAMPLE=sampledata
row.names(SAMPLE)=SAMPLE$Sample_ID

SAMPLE=subset(SAMPLE,SAMPLE$TRT=="Alone"|SAMPLE$TRT=="Inter")
SAMPLE=sample_data(SAMPLE)

### create phyloseq object
physeq.all = merge_phyloseq(mothurdata, SAMPLE) # Modified version worked


### We need to change the taxonomy names: when using the fwdb taxonomy we need to add different headers after removing the last column, which contains no information except for 1 Verrucomicrobia taxon

#   tax_table(physeq.all) <- tax_table(physeq.all)[,-7] # this removes the final column
colnames(tax_table(physeq.all))<-c("Kingdom","Phylum","Class","Order","Family","Genus")


#   tax_table(physeq.all) <-cbind(tax_table(physeq.all),row.names(tax_table(physeq.all)))

### removing non-bacterial reads (was already done in mothur, but just to be safe after merging taxonomies)
#   physeq.all <- subset_taxa(physeq.all, Kingdom == "Bacteria")
## Aggregate at the genus level, then saving ea componant externally to reload and save time.

        # physeq_genus <- physeq.all %>%
         #tax_glom(taxrank = "Genus") 

        # otu=data.frame(otu_table(physeq_genus))
        
        # meta=data.frame(sample_data(physeq_genus))
        # tax=data.frame(tax_table(physeq_genus))
        
        # write.csv(x = otu,file = "otu_table.csv",row.names = TRUE)
        # write.csv(x = tax,file = "tax_table.csv")# 
        # write.csv(x = meta,file = "sample_table.csv",row.names = F)


otu=read.csv("~/Google Drive File Stream/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output/otu_table.csv",row.names = 1)

colnames(otu)=gsub('X',"",colnames(otu))

otu=otu_table(otu,taxa_are_rows = TRUE)


tax=read.csv('~/Google Drive File Stream/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output/tax_table.csv',row.names=1)
taxRows=row.names(tax)
taxCols=colnames(tax)
tax=tax_table(as.matrix(tax))

#row.names(tax)=taxRows
#colnames(tax)=taxCols


meta=read.csv('~/Google Drive File Stream/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output/MetaDataTest.csv')
namesKeep<-colnames(otu)

row.names(meta)=meta$Sample_ID

meta=meta[which(meta$Sample_ID%in%namesKeep),]
meta=sample_data(meta)
   
physeq_genus=merge_phyloseq(otu,tax,meta)
setwd("~/Google Drive File Stream/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output")

### ADD THE PROTEOBACTERIA CLASSES TO THE PHYLA NAME FIELD IN PHYLOSEQ OBJECT TAXONOMY 

phy <- data.frame(tax_table(physeq_genus))
Phylum <- as.character(phy$Phylum)
Class <- as.character(phy$Class)
for  (i in 1:length(Phylum)){ 
  if (Phylum[i] == "Proteobacteria"){
    if (Class[i] == "unclassified"){
      Phylum[i] <- Phylum[i]       
    } else {
      Phylum[i] <- Class[i]
    }
  } 
}


Phylum<-as.character(phy$Phylum)
Class=as.character(phy$Class)
phy$Phylum=Phylum
t <- tax_table(as.matrix(phy))

Sequence depth and pruning

physeq=(physeq.all2)
physeq <- prune_taxa(taxa_sums(physeq) > 0, physeq) # Remove taxa with no counts

#check number of reads in each sample, differences in count are in part due differet numbers of chlorophyl reads depending on time of experiment

# Make a data frame with a column for the read counts of each sample
sample_sum_df <- data.frame(sum = sample_sums(physeq))

# Histogram of sample read counts
ggplot(sample_sum_df, aes(x = sum)) + 
  geom_histogram(color = "black", fill = "#59A14F", binwidth = 2500) +
  ggtitle("Distribution of sample sequencing depth") + 
  xlab("Read counts") +
  theme(axis.title.y = element_blank())+
  theme_classic()

# Scales reads to smallest library size 
source("https://raw.githubusercontent.com/michberr/MicrobeMiseq/master/R/miseqR.R")
#physeq.scale <- scale_reads(physeq, min(sample_sums(physeq)))

##### Normalization #######

# Scales reads by 
# 1) taking proportions,
# 2) multiplying by a given library size of n
# 3) rounding down
physeq1=prune_samples(sample_sums(physeq) >20000, physeq)
sample_sum_df1 <- data.frame(sum = sample_sums(physeq1))

# Histogram of sample read counts
ggplot(sample_sum_df1, aes(x = sum)) + 
  geom_histogram(color = "black", fill = "#59A14F", binwidth = 2500) +
  ggtitle("Distribution of sample sequencing depth after pruning") + 
  xlab("Read counts") +
  theme(axis.title.y = element_blank())+
  theme_classic()

n=min(sample_sums(physeq1))
  physeq.scale <-
    transform_sample_counts(physeq1, function(x) {
      (n * x/sum(x))  # Transform to rel. abundance
    })
physeq.scale <- prune_taxa(taxa_sums(physeq.scale) > 0, physeq.scale)


physeq1
## phyloseq-class experiment-level object
## otu_table()   OTU Table:         [ 1098 taxa and 173 samples ]
## sample_data() Sample Data:       [ 173 samples by 9 sample variables ]
## tax_table()   Taxonomy Table:    [ 1098 taxa by 6 taxonomic ranks ]
# Betadiv pcoa Bray-Curtis DNA only 
physeq.pcoa <-
  ordinate(
    physeq = physeq.scale,
    method = "PCoA",
    distance = "bray"
  )

physeq.pcoa.vectors <- data.frame(physeq.pcoa$vectors[, 1:4])
physeq.pcoa.vectors$Duplicates <- row.names(physeq.pcoa.vectors)
SampData=data.frame(sample_data(physeq))
colnames(SampData)[1]="Duplicates"

SampData=subset(SampData,SampData$TRT=="Inter"|SampData$TRT=="Alone")

physeq.pcoa.df <- droplevels(merge(physeq.pcoa.vectors,SampData,by="Duplicates"))
bray_values <- physeq.pcoa$values
bray_rel_eigens <- bray_values$Relative_eig
bray_rel_eigen1 <- bray_rel_eigens[1]
bray_rel_eigen1_percent <- round(bray_rel_eigen1 * 100, digits = 1)
bray_rel_eigen2 <- bray_rel_eigens[2]
bray_rel_eigen2_percent <- round(bray_rel_eigen2 * 100, digits = 1)
bray_rel_eigen3 <- bray_rel_eigens[3]
bray_rel_eigen3_percent <- round(bray_rel_eigen3 * 100, digits = 1)
bray_rel_eigen4 <- bray_rel_eigens[4]
bray_rel_eigen4_percent <- round(bray_rel_eigen4 * 100, digits = 1)
bray_rel_eigen5 <- bray_rel_eigens[5]
bray_rel_eigen5_percent <- round(bray_rel_eigen5 * 100, digits = 1)
bray_axis1 <- paste("PCoA 1:",bray_rel_eigen1_percent,"%")
bray_axis2 <- paste("PCoA 2:",bray_rel_eigen2_percent,"%")
bray_axis3 <- paste("PCoA 3:",bray_rel_eigen3_percent,"%")
bray_axis4 <- paste("PCoA 4:",bray_rel_eigen4_percent,"%")
PCoA_title <- paste("Bray-Curtis,",ntaxa(physeq.scale),"OTUs")


pcoa_exp_trt <- ggplot(physeq.pcoa.df, aes(Axis.1, Axis.2, color = TRT,fill = TRT)) +
  xlab(bray_axis1) + 
  ylab(bray_axis2) +
  geom_point(alpha=0.9) + 
  theme_classic() +
  scale_fill_manual(values = c("#00B050","grey"),"Treatment", labels = c("Alone", "Competition"))+
  scale_color_manual(values = c("#00B050","grey"),"Treatment", labels = c("Alone", "Competition"))+
  stat_ellipse(geom = "polygon", alpha = 1/6, aes(fill =TRT))+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))
#  scale_fill_discrete(name = "Treatment", labels = c("Alone", "Competition"))+
 # scale_color_discrete(name = "Treatment", labels = c("Alone", "Competition"))



pcoa_exp_trtA <- ggplot(physeq.pcoa.df, aes(Axis.3, Axis.4, color = TRT,fill = TRT)) +
  xlab(bray_axis3) + 
  ylab(bray_axis4) + 
  geom_point(alpha=0.9) + 
  theme_classic() +
  scale_fill_manual(values = GoldGrey,"Treatment", labels = c("Alone", "Competition"))+
  scale_color_manual(values = GoldGrey,"Treatment", labels = c("Alone", "Competition"))+
  stat_ellipse(geom = "polygon", alpha = 1/6, aes(fill =TRT))+
  Tx


pcoa_exp_sp <- ggplot(physeq.pcoa.df, aes(Axis.1, Axis.2, color = Species,fill = Species)) +
  xlab("") + 
  ylab(bray_axis2) +
  geom_point(alpha=0.9) + 
  theme_classic() +
 scale_fill_manual(values = GreenBlue,"Species", labels = c("I. hederacea", "I. purpurea"))+
  scale_color_manual(values = GreenBlue,"Species", labels = c("I. hederacea", "I. purpurea"))+
   stat_ellipse(geom = "polygon", alpha = 1/6, aes(fill =Species))+
  Tx


pcoa_exp_spA <- ggplot(physeq.pcoa.df, aes(Axis.3, Axis.4, color = Species,fill = Species)) +
  xlab("") + 
  ylab(bray_axis4) +
  geom_point(alpha=0.9) + 
  theme_classic()+
  scale_fill_manual(values = GreenBlue,"Species", labels = c("I. hederacea", "I. purpurea"))+
  scale_color_manual(values = GreenBlue,"Species", labels = c("I. hederacea", "I. purpurea"))+
  stat_ellipse(geom = "polygon", alpha = 1/6, aes(fill =Species))+
  Tx

dev.off()
FALSE null device 
FALSE           1
A=ggarrange(pcoa_exp_trt,pcoa_exp_trtA,common.legend = T,labels=c("C","D"),font.label = list(size = 15, color = "black", face =
  "plain"),hjust = -8,vjust=1)
B=ggarrange(pcoa_exp_sp,pcoa_exp_spA,common.legend = T,labels=c("A","B"),font.label = list(size = 15, color = "black", face =
  "plain"),hjust = -8,vjust=1)

MainFig=ggarrange(B,A,nrow=2)

annotate_figure(MainFig,
                top = text_grob(PCoA_title, face = "plain", size = 25,lineheight = 2)
)
physeq.pcoa.df$TrtSp=paste(physeq.pcoa.df$TRT,physeq.pcoa.df$Species,sep="")

p <- plot_ly(physeq.pcoa.df, x = ~Axis.1, y = ~Axis.2, z = ~Axis.3, color = ~TrtSp) %>%
  add_markers() %>%
  layout(scene = list(xaxis = list(title = bray_axis1),
                     yaxis = list(title = bray_axis2),
                     zaxis = list(title = bray_axis3)))


p1 <- plot_ly(physeq.pcoa.df, x = ~Axis.1, y = ~Axis.2, z = ~Axis.4, color = ~Species) %>%
  add_markers() %>%
  layout(scene = list(xaxis = list(title = bray_axis1),
                     yaxis = list(title = bray_axis2),
                     zaxis = list(title = bray_axis4)))

p3 <- plot_ly(physeq.pcoa.df, x = ~Axis.1, y = ~Axis.2, z = ~Axis.4, color = ~Species) %>%
  add_markers() %>%
  layout(scene = list(xaxis = list(title = bray_axis1),
                     yaxis = list(title = bray_axis3),
                     zaxis = list(title = bray_axis4)))
## All experiment, add variable treatment, then species
sampledf <- data.frame(sample_data(physeq.scale))
sampledf=subset(sampledf,sampledf$TRT=="Alone"|sampledf$TRT=="Inter")

## Subsample by species 
physeq.purp=subset_samples(physeq.scale, Species == "Ip")
physeq.hed=subset_samples(physeq.scale, Species != "Ip")

## Subsample within competition
physeq.comp=subset_samples(physeq.scale, TRT=="Inter")

# Calculate bray curtis for experimental samples only
physeq.bray <- phyloseq::distance(physeq = physeq.scale, method = "bray") # acrosss species and treatment
physeq.bray2 <- phyloseq::distance(physeq = physeq.purp, method = "bray") # within Ipurp
physeq.bray2b <- phyloseq::distance(physeq = physeq.hed, method = "bray") # within Ipurp

physeq.bray3 <- phyloseq::distance(physeq = physeq.comp, method = "bray") # within competition

sampledf$Comp=sub(".*\\-","",sampledf$Combos)

# Adonis test for treatment, across species
adonis(physeq.bray ~ TRT, data = sampledf)
FALSE 
FALSE Call:
FALSE adonis(formula = physeq.bray ~ TRT, data = sampledf) 
FALSE 
FALSE Permutation: free
FALSE Number of permutations: 999
FALSE 
FALSE Terms added sequentially (first to last)
FALSE 
FALSE            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
FALSE TRT         1    0.0291 0.029087 0.89564 0.00521  0.494
FALSE Residuals 171    5.5533 0.032476         0.99479       
FALSE Total     172    5.5824                  1.00000
b = betadisper(physeq.bray,sampledf$TRT)

p <- permutest(b)
p$tab
FALSE            Df      Sum Sq     Mean Sq        F N.Perm Pr(>F)
FALSE Groups      1 0.004538395 0.004538395 1.602334    999  0.196
FALSE Residuals 171 0.484334618 0.002832366       NA     NA     NA
# Adonis test for treatment, WITHIN species
adonis(physeq.bray2 ~ TRT+Block, data = sampledf%>%filter(Species=="Ip")) # No treatment effect on bray distances
FALSE 
FALSE Call:
FALSE adonis(formula = physeq.bray2 ~ TRT + Block, data = sampledf %>%      filter(Species == "Ip")) 
FALSE 
FALSE Permutation: free
FALSE Number of permutations: 999
FALSE 
FALSE Terms added sequentially (first to last)
FALSE 
FALSE           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)    
FALSE TRT        1    0.0258 0.025835  0.8460 0.00796  0.549    
FALSE Block      3    0.3189 0.106312  3.4813 0.09826  0.001 ***
FALSE Residuals 95    2.9011 0.030538         0.89378           
FALSE Total     99    3.2459                  1.00000           
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
b = betadisper(physeq.bray,sampledf$TRT)
p <- permutest(b)
p$tab
FALSE            Df      Sum Sq     Mean Sq        F N.Perm Pr(>F)
FALSE Groups      1 0.004538395 0.004538395 1.602334    999  0.215
FALSE Residuals 171 0.484334618 0.002832366       NA     NA     NA
# Adonis test for treatment, WITHIN species
adonis(physeq.bray2 ~ TRT+Block*ML, data = sampledf%>%filter(Species=="Ip")) # No treatment effect on bray distances
FALSE 
FALSE Call:
FALSE adonis(formula = physeq.bray2 ~ TRT + Block * ML, data = sampledf %>%      filter(Species == "Ip")) 
FALSE 
FALSE Permutation: free
FALSE Number of permutations: 999
FALSE 
FALSE Terms added sequentially (first to last)
FALSE 
FALSE           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)    
FALSE TRT        1    0.0258 0.025835  0.8539 0.00796  0.543    
FALSE Block      3    0.3189 0.106312  3.5139 0.09826  0.001 ***
FALSE ML         9    0.2367 0.026301  0.8693 0.07293  0.757    
FALSE Block:ML  22    0.7281 0.033097  1.0939 0.22432  0.195    
FALSE Residuals 64    1.9363 0.030254         0.59653           
FALSE Total     99    3.2459                  1.00000           
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
adonis(physeq.bray2b ~ Block*ML, data = sampledf%>%filter(Species!="Ip")) # No treatment effect on bray distances
FALSE 
FALSE Call:
FALSE adonis(formula = physeq.bray2b ~ Block * ML, data = sampledf %>%      filter(Species != "Ip")) 
FALSE 
FALSE Permutation: free
FALSE Number of permutations: 999
FALSE 
FALSE Terms added sequentially (first to last)
FALSE 
FALSE           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)    
FALSE Block      3   0.22002 0.073340 2.49402 0.09648  0.001 ***
FALSE ML         4   0.07412 0.018530 0.63013 0.03250  0.975    
FALSE Block:ML   9   0.33957 0.037730 1.28305 0.14890  0.035 *  
FALSE Residuals 56   1.64675 0.029406         0.72211           
FALSE Total     72   2.28046                  1.00000           
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Adonis test for species 
set.seed(7L)
adonis(physeq.bray3 ~ Species+Block*ML, data = sampledf%>%filter(TRT=="Inter"))
FALSE 
FALSE Call:
FALSE adonis(formula = physeq.bray3 ~ Species + Block * ML, data = sampledf %>%      filter(TRT == "Inter")) 
FALSE 
FALSE Permutation: free
FALSE Number of permutations: 999
FALSE 
FALSE Terms added sequentially (first to last)
FALSE 
FALSE            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)    
FALSE Species     1    0.0528 0.052832  1.7517 0.01095  0.049 *  
FALSE Block       3    0.3790 0.126343  4.1890 0.07855  0.001 ***
FALSE ML         13    0.3674 0.028262  0.9370 0.07614  0.665    
FALSE Block:ML   32    1.1304 0.035325  1.1712 0.23427  0.050 *  
FALSE Residuals  96    2.8955 0.030161         0.60008           
FALSE Total     145    4.8251                  1.00000           
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
b = betadisper(physeq.bray3,( sampledf%>%filter(TRT=="Inter"))$Species)
p <- permutest(b)
p$tab
FALSE            Df      Sum Sq     Mean Sq        F N.Perm Pr(>F)
FALSE Groups      1 0.003812412 0.003812412 1.279186    999  0.246
FALSE Residuals 144 0.429169301 0.002980342       NA     NA     NA
sampledf$Block=as.factor(sampledf$Block)
sampledf$Comp=as.factor(sampledf$Comp)
# # # # # # # # # # # # # # # # # # # # # 
#             ACROSS SAMPLES
amova(physeq.bray ~ TRT, data = sampledf) # Across all samples
## 
##  Analysis of Molecular Variance
## 
## Call: amova(formula = physeq.bray ~ TRT, data = sampledf)
## 
##              SSD        MSD  df
## TRT   0.02908666 0.02908666   1
## Error 5.55333864 0.03247566 171
## Total 5.58242529 0.03245596 172
## 
## Variance components:
##            sigma2 P.value
## TRT   -7.4366e-05  0.4895
## Error  3.2476e-02        
## 
## Phi-statistics:
## TRT.in.GLOBAL 
##  -0.002295142 
## 
## Variance coefficients:
##        a 
## 45.57225
amova(physeq.bray ~ Species, data = sampledf) # Across all samples
## Warning in amova(physeq.bray ~ Species, data = sampledf): elements in the rhs of
## the formula are not all factors
## 
##  Analysis of Molecular Variance
## 
## Call: amova(formula = physeq.bray ~ Species, data = sampledf)
## 
##                SSD        MSD  df
## Species 0.05608391 0.05608391   1
## Error   5.52634139 0.03231779 171
## Total   5.58242529 0.03245596 172
## 
## Variance components:
##             sigma2 P.value
## Species 0.00028161  0.0639
## Error   0.03231779        
## 
## Phi-statistics:
## Species.in.GLOBAL 
##       0.008638573 
## 
## Variance coefficients:
##        a 
## 84.39306
# # # # # # # # # # # # # # # # # # # # # 
# Subsample for within I. purpurea only
# # # # # # # # # # # # # # # # # # # # # 

physeq.Purp <- subset_samples(physeq.scale, Species == "Ip")
sampledf.Purp<- data.frame(sample_data(physeq.Purp))
# Calculate bray curtis for summer samples only
physeq.Purp.bray <- phyloseq::distance(physeq = physeq.Purp, method = "bray")
amova(physeq.Purp.bray ~ TRT, data = sampledf.Purp) # Across all samples
## 
##  Analysis of Molecular Variance
## 
## Call: amova(formula = physeq.Purp.bray ~ TRT, data = sampledf.Purp)
## 
##              SSD        MSD df
## TRT   0.02583514 0.02583514  1
## Error 3.22005058 0.03285766 98
## Total 3.24588571 0.03278672 99
## 
## Variance components:
##            sigma2 P.value
## TRT   -0.00017815  0.6184
## Error  0.03285766        
## 
## Phi-statistics:
## TRT.in.GLOBAL 
##  -0.005451311 
## 
## Variance coefficients:
##     a 
## 39.42
# # # # # # # # # # # # # # # # # # # # # 
# Subsample for within competition
# # # # # # # # # # # # # # # # # # # # # 

physeq.Comp <- subset_samples(physeq.scale, TRT=="Inter")
sampledf.Comp<- data.frame(sample_data(physeq.Comp))
# Calculate bray curtis for summer samples only
physeq.Comp.bray <- phyloseq::distance(physeq = physeq.Comp, method = "bray")
amova(physeq.Comp.bray ~ Species, data = sampledf.Comp) # marginal species differences
## Warning in amova(physeq.Comp.bray ~ Species, data = sampledf.Comp): elements in
## the rhs of the formula are not all factors
## 
##  Analysis of Molecular Variance
## 
## Call: amova(formula = physeq.Comp.bray ~ Species, data = sampledf.Comp)
## 
##                SSD        MSD  df
## Species 0.05283239 0.05283239   1
## Error   4.77230564 0.03314101 144
## Total   4.82513803 0.03327681 145
## 
## Variance components:
##             sigma2 P.value
## Species 0.00026974  0.0979
## Error   0.03314101        
## 
## Phi-statistics:
## Species.in.GLOBAL 
##       0.008073593 
## 
## Variance coefficients:
##  a 
## 73

Test for differently abundant OTUs

Visualize the different groups at the family level

# Check for 'core' microbiome members as the phylum level which taxa are present
# at 1 % overall abundance and at least 75% of samples 

PhylumGlom<-tax_glom(physeq.Purp,taxrank="Phylum")
FamGlom<-tax_glom(physeq.Purp,taxrank="Family")
ClassGlom<-tax_glom(physeq.Purp,taxrank="Class")


coreTaxa = filter_taxa(PhylumGlom, function(x) sum(x > 1) > (0.75 * length(x)), TRUE)
coreTaxaFamily = filter_taxa(FamGlom, function(x) sum(x > 1) > (0.75 * length(x)), TRUE)

## Plot at phylum level


physeq1_phylumAlone <- coreTaxa  %>%
  subset_samples(TRT=="Alone")%>%
  transform_sample_counts(function(x) {x/sum(x)} ) %>% # Transform to rel. abundance
  psmelt()      


physeq1_phylumComp <- coreTaxa  %>%
  subset_samples(TRT!="Alone")%>%
  transform_sample_counts(function(x) {x/sum(x)} ) %>% # Transform to rel. abundance
  psmelt()       

physeq1_phylum<-rbind(physeq1_phylumAlone,physeq1_phylumComp)

# Melt to long format
physeq1_phylum=physeq1_phylum[order(physeq1_phylum$Phylum),] 

#colnames(physeq1_phylum)[13]="Phylum"

# Sort data frame alphabetically by phylum
# Set colors for plotting
phylum_colors <- c(
  "#CBD588", "#5F7FC7", "orange","#DA5724", "#508578", "#CD9BCD",
   "#AD6F3B", "#673770","#D14285", "#652926", "#C84248", 
  "#8569D5", "#5E738F","#D1A33D", "#8A7C64", "#599861"
)


#colnames(physeq1_phylum)[which(names(physeq1_phylum)%in%"Rank2")]="Phylum"

# Plot 
ggplot(physeq1_phylum, aes(x = TRT, y = Abundance, fill = Phylum)) + 
  geom_bar(stat = "identity",position='dodge')+
  #scale_fill_manual(values = phylum_colors)+
  theme(axis.title.x = element_blank()) + 
  ylab("Relative Abundance (Phyla > 75 %) \n") +
  ggtitle("Phylum Composition  \n Bacterial Communities by Sampling per Treatment") +
  theme_classic()+
  ylab("Relative Abundance")

Testing if different at the phylum level

PhlyaList<-as.list(unique(physeq1_phylum$Phylum))

KrusMicrTest<-function(Microbe){
  Result=kruskal.test(Abundance ~ TRT, data = physeq1_phylum[which(physeq1_phylum$Phylum==Microbe),]) 

ResDf=data.frame("ChiSq"=Result$statistic,"Pval"=Result$p.value,"Phylum"=paste(Microbe))  
  return(ResDf)  
}

AllResults=lapply(PhlyaList,KrusMicrTest)
KruskalRes=do.call('rbind',AllResults)

Family level

# Family level
physeq1_FamilyAlone <- coreTaxaFamily  %>%
  subset_samples(TRT=="Alone")%>%
  transform_sample_counts(function(x) {x/sum(x)} ) %>% # Transform to rel. abundance
  psmelt()                                      # Melt to long format

physeq1_FamilyComp <- coreTaxaFamily  %>%
  subset_samples(TRT!="Alone")%>%
  transform_sample_counts(function(x) {x/sum(x)} ) %>% # Transform to rel. abundance
  psmelt()       

physeq1_Family<-rbind(physeq1_FamilyAlone,physeq1_FamilyComp)


FamList<-as.list(unique(physeq1_Family$Family))

KrusMicrTest<-function(Microbe){
  Result=kruskal.test(Abundance ~ TRT, data = physeq1_Family[which(physeq1_Family$Family==Microbe),]) 

ResDf=data.frame("ChiSq"=Result$statistic,"Pval"=Result$p.value,"Family"=paste(Microbe))  
  return(ResDf)  
}

AllResultsFamily=lapply(FamList,KrusMicrTest)
KruskalResFamily=do.call('rbind',AllResultsFamily)

KruskalResFamily%>%filter(Pval<0.055)
##      ChiSq        Pval          Family
## 1 5.192655 0.022682540   Subgroup_2_fa
## 2 3.904351 0.048161234     Gaiellaceae
## 3 3.752445 0.052730323  Lineage_IIa_fa
## 4 4.186783 0.040740338          SM2D12
## 5 4.509080 0.033715377        AKYG1722
## 6 3.904351 0.048161234 Microtrichaceae
## 7 8.682062 0.003213572           A0839
# Do false discovery rate for mulitple corrections

KruskalResFamily$AdjPval=p.adjust(KruskalResFamily$Pval, method = "fdr", n = 213)

Alpha diversity

hist(sample_sums(physeq1))

# Remove sample with less than 20K reads, this looks WAAAY off
# Rarify first
ps.rarefied=rarefy_even_depth(physeq1,rngseed=1,sample.size=min(sample_sums(physeq1)),replace=F)

plot_richness(ps.rarefied,x="TRT",measures=c("Observed","Shannon"))+
  geom_boxplot()+
  theme_classic()

Alpha Diversity

Note: Measures of alpha-diversity

Inverse Simpson it is an indication of the richness in a community with uniform evenness that would have the same level of diversity. So while measures such as the Shannon index are somewhat abstract, the inverse of the Simpson index has some biological interpretation. Other advantages of the Simpson-based metrics are that they do not tend to be as affected by sampling effort as the Shannon index.

  • Species richness is simply a count of species, and it does not take into account the abundances of the species or their relative abundance distributions.

  • Simpson’s Diversity Index is a measure of diversity which takes into account the number of species present, as well as the relative abundance of each species. As species richness and evenness increase,so diversity increases.

### I commented out the subsampling to save time. The matrices produced were saved and then reoponed from their tab delmited formats into corresponding matrices.

set.seed(3)

r <- rarefy_even_depth(physeq1, sample.size = n, verbose = FALSE, replace = TRUE)
         
 ## Calculate richness
rich <- as.numeric(as.matrix(estimate_richness(r, measures = "Observed")))

## Calculate Inverse Simpson

simp <- as.numeric(as.matrix(estimate_richness(r, measures = "InvSimpson")))

sim<- as.numeric(as.matrix(estimate_richness(r, measures = "Simpson")))

s <- rarefy_even_depth(physeq1, sample.size = n, verbose = FALSE, replace = TRUE)
shan <- as.numeric(as.matrix(estimate_richness(r, measures = "Shannon")))

InvSimp=simp
# Create a new dataframe to hold the means and standard deviations of richness estimates
length(rich)
## [1] 173
Sample_ID <- sample_names(physeq1)
Block <-sample_data(physeq1)$Block
Species <-sample_data(physeq1)$Species
TRT <-sample_data(physeq1)$TRT
Combos <-sample_data(physeq1)$Combos
ML <-sample_data(physeq1)$ML

alpha=data.frame(Sample_ID,ML,Block,TRT,Species,Combos,rich,InvSimp,sim,shan)

alpha$even=alpha$shan/alpha$rich

# DO VIOLIN PLOT HERE!!!


p=ggplot(alpha%>%filter(TRT=="Inter"), aes(x=Species, y=rich)) +
  geom_violin(trim=FALSE,aes(fill=Species),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=Species,fill=Species))+
  theme_classic()+
  scale_color_brewer(palette = "Paired")+
  scale_fill_brewer(palette = "Paired")+
  ggtitle("Mean Species Richness")


q=ggplot(alpha%>%filter(TRT=="Inter"), aes(x=Species, y=InvSimp)) +
  geom_violin(trim=FALSE,aes(fill=Species),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=Species,fill=Species))+
  theme_classic()+
  scale_color_brewer(palette = "Paired")+
  scale_fill_brewer(palette = "Paired")+
  ggtitle("Mean Species Inverse Simpson")+
  ylab("")


t=ggplot(alpha%>%filter(TRT=="Inter"), aes(x=Species, y=sim)) +
  geom_violin(trim=FALSE,aes(fill=Species),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=Species,fill=Species))+
  theme_classic()+
  scale_color_brewer(palette = "Paired")+
  scale_fill_brewer(palette = "Paired")+
  ggtitle("Mean Simpson")+
  ylab("")

v=ggplot(alpha%>%filter(TRT=="Inter"), aes(x=Species, y=even)) +
  geom_violin(trim=FALSE,aes(fill=Species),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=Species,fill=Species))+
  theme_classic()+
  scale_color_brewer(palette = "Paired")+
  scale_fill_brewer(palette = "Paired")+
  ggtitle("Mean Evenness")+
  ylab("")



ggarrange(p,q,t,v,common.legend=T,ncol=2,nrow=2)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.

      ### Treatment

pT=ggplot(alpha%>%filter(Species=="Ip"), aes(x=TRT, y=rich)) +
  geom_violin(trim=FALSE,aes(fill=TRT),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=TRT,fill=TRT))+
  theme_classic()+
  scale_color_manual(values=c("#B2DF8A","#fee090"))+
  scale_fill_manual(values=c("#B2DF8A","#fee090"))+
  ggtitle("Mean Treatment Richness")


qT=ggplot(alpha%>%filter(Species=="Ip"), aes(x=TRT, y=InvSimp)) +
  geom_violin(trim=FALSE,aes(fill=TRT),alpha=0.3)+ 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1,aes(color=TRT,fill=TRT))+
  theme_classic()+
  scale_color_manual(values = c("#B2DF8A","#fee090"))+
  scale_fill_manual(values = c("#B2DF8A","#fee090"))+
  ggtitle("Mean Treatment Inverse Simpson")+
  ylab(" ")

ggarrange(pT,qT,common.legend=T)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.

Test for differences

# first check for normality. To test for normalcy statistically, we can run the Shapiro-Wilk test of normality.

shapiro.test(alpha$rich) # Not normal
FALSE 
FALSE   Shapiro-Wilk normality test
FALSE 
FALSE data:  alpha$rich
FALSE W = 0.98897, p-value = 0.1974
shapiro.test(alpha$even) # Normal
FALSE 
FALSE   Shapiro-Wilk normality test
FALSE 
FALSE data:  alpha$even
FALSE W = 0.97645, p-value = 0.004898
shapiro.test(alpha$sim) # Normal
FALSE 
FALSE   Shapiro-Wilk normality test
FALSE 
FALSE data:  alpha$sim
FALSE W = 0.90086, p-value = 2.238e-09
histogram(alpha$rich,xlab="Richness") # Note richness though, not normal, looks close to normal.

histogram(alpha$InvSimp,xlab="Inverse-Simpson")

histogram(alpha$sim,xlab="Simpson")

#   Run the ANOVA and save it as an object

# Test for species within competition
aov.Richness = aov(rich~Species+Block,alpha%>%filter(TRT=="Inter"))
aov.simpsonInv = aov(InvSimp~Species+Block,alpha%>%filter(TRT=="Inter"))
aov.simpson = aov(sim~Species+Block,alpha%>%filter(TRT=="Inter"))
aov.evenness = aov(even~Species+Block,alpha%>%filter(TRT=="Inter"))
aov.shannon = aov(shan~Species+Block,alpha%>%filter(TRT=="Inter"))

#Call for the summary of that ANOVA, which will include P-values
summary(aov.Richness)
FALSE              Df Sum Sq Mean Sq F value   Pr(>F)    
FALSE Species       1    144     144   0.184 0.668475    
FALSE Block         3  15795    5265   6.733 0.000281 ***
FALSE Residuals   141 110255     782                     
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aov.simpsonInv)
FALSE              Df Sum Sq Mean Sq F value  Pr(>F)   
FALSE Species       1    145   144.7   1.676 0.19752   
FALSE Block         3   1038   345.9   4.007 0.00898 **
FALSE Residuals   141  12172    86.3                   
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aov.simpson)
FALSE              Df   Sum Sq   Mean Sq F value Pr(>F)  
FALSE Species       1 0.000032 3.249e-05   0.499 0.4810  
FALSE Block         3 0.000487 1.623e-04   2.493 0.0626 .
FALSE Residuals   141 0.009177 6.509e-05                 
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aov.evenness)
FALSE              Df    Sum Sq   Mean Sq F value   Pr(>F)    
FALSE Species       1 2.940e-07 2.941e-07   1.732 0.190243    
FALSE Block         3 3.552e-06 1.184e-06   6.974 0.000208 ***
FALSE Residuals   141 2.393e-05 1.697e-07                     
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aov.shannon)
FALSE              Df Sum Sq Mean Sq F value  Pr(>F)   
FALSE Species       1  0.009 0.00925   0.296 0.58710   
FALSE Block         3  0.370 0.12345   3.955 0.00961 **
FALSE Residuals   141  4.402 0.03122                   
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# No significant differences


# Test for treatment within I. purpurea
alpha.purp<-alpha%>%filter(Species=="Ip")

aov.Richness = lm(rich~TRT+Block,alpha.purp)
aov.simpsonInv = lm(InvSimp~TRT+Block,alpha.purp)
aov.simpson = lm(sim~TRT+Block,alpha.purp)
aov.evenness = lm(even~TRT+Block,alpha.purp)
aov.shannon = lm(shan~TRT+Block,alpha.purp)


#Call for the summary of that ANOVA, which will include P-values
anova(aov.Richness)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: rich
FALSE           Df Sum Sq Mean Sq F value   Pr(>F)   
FALSE TRT        1    796   796.2  0.8580 0.356657   
FALSE Block      3  15895  5298.2  5.7094 0.001229 **
FALSE Residuals 95  88158   928.0                    
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.simpsonInv)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: InvSimp
FALSE           Df Sum Sq Mean Sq F value   Pr(>F)   
FALSE TRT        1    0.3    0.33  0.0038 0.950870   
FALSE Block      3 1064.0  354.66  4.1296 0.008463 **
FALSE Residuals 95 8158.8   85.88                    
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.simpson)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: sim
FALSE           Df    Sum Sq    Mean Sq F value  Pr(>F)  
FALSE TRT        1 0.0000215 2.1498e-05  0.3573 0.55143  
FALSE Block      3 0.0005168 1.7225e-04  2.8629 0.04084 *
FALSE Residuals 95 0.0057158 6.0166e-05                  
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.evenness)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: even
FALSE           Df     Sum Sq    Mean Sq F value   Pr(>F)   
FALSE TRT        1 1.1710e-07 1.1708e-07  0.5761 0.449707   
FALSE Block      3 2.9070e-06 9.6899e-07  4.7684 0.003857 **
FALSE Residuals 95 1.9305e-05 2.0321e-07                    
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# No significant differences


# Model accross species and treatment 
aov.Richness = aov(rich~TRT+Species+Block,alpha)
aov.simpsonInv = aov(InvSimp~TRT+Species+Block,alpha)
aov.simpson = aov(sim~TRT+Species+Block,alpha)
aov.evenness = aov(even~TRT+Species+Block,alpha)
aov.shannon = aov(shan~TRT+Species+Block,alpha)


#Call for the summary of that ANOVA, which will include P-values
anova(aov.Richness)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: rich
FALSE            Df Sum Sq Mean Sq F value   Pr(>F)    
FALSE TRT         1    655   655.2  0.8179   0.3671    
FALSE Species     1    144   144.0  0.1797   0.6721    
FALSE Block       3  20181  6726.9  8.3964 3.13e-05 ***
FALSE Residuals 167 133794   801.2                     
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.simpsonInv)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: InvSimp
FALSE            Df  Sum Sq Mean Sq F value   Pr(>F)   
FALSE TRT         1    17.1   17.11  0.2112 0.646446   
FALSE Species     1   144.7  144.71  1.7857 0.183267   
FALSE Block       3  1089.9  363.31  4.4832 0.004694 **
FALSE Residuals 167 13533.5   81.04                    
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.simpson)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: sim
FALSE            Df    Sum Sq    Mean Sq F value  Pr(>F)  
FALSE TRT         1 0.0000524 5.2377e-05  0.8799 0.34958  
FALSE Species     1 0.0000325 3.2494e-05  0.5459 0.46104  
FALSE Block       3 0.0005244 1.7480e-04  2.9365 0.03494 *
FALSE Residuals 167 0.0099410 5.9527e-05                  
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(aov.evenness)
FALSE Analysis of Variance Table
FALSE 
FALSE Response: even
FALSE            Df     Sum Sq    Mean Sq F value    Pr(>F)    
FALSE TRT         1 2.3600e-08 2.3610e-08  0.1311    0.7177    
FALSE Species     1 2.9410e-07 2.9407e-07  1.6328    0.2031    
FALSE Block       3 4.4640e-06 1.4880e-06  8.2619 3.707e-05 ***
FALSE Residuals 167 3.0077e-05 1.8010e-07                      
FALSE ---
FALSE Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# summary(aov.shannon)



# Boxplot
ggplot(alpha%>%filter(Species=="Ip"),aes(TRT,rich))+
  geom_boxplot()+
  theme_bw()+
  ylab("Richness")+
  xlab("")+
  scale_x_discrete(labels=c("Alone","Competition"))+
  theme(axis.text.x = element_text(vjust = -1),axis.text=element_text(size=20),axis.title=element_text(size=30),axis.title.x = element_text(vjust=-1))+
  Margin

ggplot(alpha%>%filter(Species=="Ip"),aes(TRT,even))+
  geom_boxplot()+
  theme_bw()+
  ylab("Evenness")+
  xlab("")+
  scale_x_discrete(labels=c("Alone","Competition"))+
  theme(axis.text.x = element_text(vjust = -1),axis.text=element_text(size=20),axis.title=element_text(size=30),axis.title.x = element_text(vjust=-1))+
  Margin

ggplot(alpha%>%filter(Species=="Ip"),aes(TRT,sim))+
  geom_boxplot()+
  theme_bw()+
  ylab("Simpson")+
  xlab("")+
  scale_x_discrete(labels=c("Alone","Competition"))+
  theme(axis.text.x = element_text(vjust = -1),axis.text=element_text(size=20),axis.title=element_text(size=30),axis.title.x = element_text(vjust=-1))+
  Margin

ggplot(alpha%>%filter(Species=="Ip"),aes(TRT,InvSimp))+
  geom_boxplot()+
  theme_bw()+
  ylab("Inverse Simpson")+
  xlab("")+
  scale_x_discrete(labels=c("Alone","Competition"))+
  theme(axis.text.x = element_text(vjust = -1),axis.text=element_text(size=20),axis.title=element_text(size=30),axis.title.x = element_text(vjust=-1))+
  Margin

Linear mixed models

# Test for treatment within I. purpurea


RichLmm = lmer(rich~TRT+Block+(1|Block:ML),alpha%>%filter(Species=="Ip"))
InvLmm = lmer(InvSimp~TRT+Block+(1|Block:ML),alpha%>%filter(Species=="Ip"))
SimLmm = lmer(sim~TRT+Block+(1|Block:ML),alpha%>%filter(Species=="Ip"))
EvenLmm = lmer(even~TRT+Block+(1|Block:ML),alpha%>%filter(Species=="Ip"))
## boundary (singular) fit: see ?isSingular
anova(RichLmm)
## Type III Analysis of Variance Table with Satterthwaite's method
##        Sum Sq Mean Sq NumDF  DenDF F value   Pr(>F)   
## TRT    1129.9  1129.9     1 87.699  1.2493 0.266729   
## Block 14252.4  4750.8     3 27.782  5.2530 0.005343 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(RichLmm)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## rich ~ TRT + Block + (1 | Block:ML)
##                npar  logLik    AIC      LRT Df Pr(>Chisq)
## <none>            7 -467.25 948.49                       
## (1 | Block:ML)    6 -467.29 946.58 0.089955  1     0.7642
anova(InvLmm)
## Type III Analysis of Variance Table with Satterthwaite's method
##       Sum Sq Mean Sq NumDF  DenDF F value  Pr(>F)  
## TRT     2.27   2.269     1 80.987  0.0301 0.86273  
## Block 706.55 235.516     3 23.542  3.1234 0.04503 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(InvLmm)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## InvSimp ~ TRT + Block + (1 | Block:ML)
##                npar  logLik    AIC    LRT Df Pr(>Chisq)
## <none>            7 -353.56 721.12                     
## (1 | Block:ML)    6 -354.24 720.48 1.3546  1     0.2445
anova(SimLmm)
## Type III Analysis of Variance Table with Satterthwaite's method
##           Sum Sq    Mean Sq NumDF  DenDF F value Pr(>F)
## TRT   0.00002586 2.5859e-05     1 78.161  0.5091 0.4776
## Block 0.00031682 1.0561e-04     3 22.168  2.0793 0.1319
ranova(SimLmm)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## sim ~ TRT + Block + (1 | Block:ML)
##                npar logLik     AIC    LRT Df Pr(>Chisq)
## <none>            7 319.86 -625.72                     
## (1 | Block:ML)    6 318.90 -625.80 1.9211  1     0.1657
anova(EvenLmm)
## Type III Analysis of Variance Table with Satterthwaite's method
##          Sum Sq    Mean Sq NumDF DenDF F value   Pr(>F)   
## TRT   1.484e-07 1.4840e-07     1    95  0.7303 0.394939   
## Block 2.907e-06 9.6899e-07     3    95  4.7684 0.003857 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(EvenLmm)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## even ~ TRT + Block + (1 | Block:ML)
##                npar logLik     AIC LRT Df Pr(>Chisq)
## <none>            7 589.21 -1164.4                  
## (1 | Block:ML)    6 589.21 -1166.4   0  1          1

Continous data (root traits, leaf number)

Here, I correlate leaf number to OTUs with at least 5% relative abundance in at least one sample in our data set.

LeafData<-read.csv("~/Google Drive File Stream/My Drive/Field_2018/Field_2018_Rcode/CharacterDisplacementRootTraits/CleanData/SizeFitData.csv")

LeafData$Sample_ID=paste(LeafData$Position,ifelse(grepl("Ihed",LeafData$ML),"H","P"),sep="")
## Additional estimates of alpha diversity
 # Specify a few:
AlphaExtra=estimate_richness(physeq1, measures=c("Observed", "InvSimpson", "Shannon", "Chao1"))

Preliminary test with roots

RootData=read.csv("~/Google Drive File Stream/My Drive/Baucom Lab /Chapter3MicrobiomeMothur/Microbiome_2018/DataSets/MothurOutput_Mock_Microbiome/Microbiome_Output/RootTraits_PCs.csv")

RootAlphaObs=merge(alpha,RootData[c("Sample_ID","PC1","PC2","PC3","PC4")])

SimpPC1=lm(sim~PC1+Species+TRT+Block,RootAlphaObs) 
summary(SimpPC1)
## 
## Call:
## lm(formula = sim ~ PC1 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.029870 -0.003809  0.002029  0.005361  0.012419 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.9769760  0.0035609 274.366   <2e-16 ***
## PC1          0.0004790  0.0007839   0.611   0.5428    
## SpeciesIp   -0.0001971  0.0018501  -0.107   0.9154    
## TRTInter    -0.0031596  0.0023507  -1.344   0.1823    
## Block2      -0.0031756  0.0067999  -0.467   0.6416    
## Block3      -0.0051282  0.0069792  -0.735   0.4644    
## Block4      -0.0041017  0.0019957  -2.055   0.0428 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007975 on 89 degrees of freedom
## Multiple R-squared:  0.07918,    Adjusted R-squared:  0.01711 
## F-statistic: 1.276 on 6 and 89 DF,  p-value: 0.2767
SimpInvPC1=lm(InvSimp~PC1+Species+TRT+Block,RootAlphaObs) 
summary(SimpInvPC1)
## 
## Call:
## lm(formula = InvSimp ~ PC1 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.7250  -6.1683   0.8967   5.7030  25.1023 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  42.5076     4.0523  10.490   <2e-16 ***
## PC1           0.6858     0.8921   0.769   0.4441    
## SpeciesIp     0.5410     2.1054   0.257   0.7978    
## TRTInter     -2.3764     2.6751  -0.888   0.3767    
## Block2       -4.7350     7.7383  -0.612   0.5422    
## Block3       -6.3293     7.9424  -0.797   0.4276    
## Block4       -4.8285     2.2711  -2.126   0.0363 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.075 on 89 degrees of freedom
## Multiple R-squared:  0.0808, Adjusted R-squared:  0.01883 
## F-statistic: 1.304 on 6 and 89 DF,  p-value: 0.2637
RichPC1=lm(rich~PC1+Species+TRT+Block,RootAlphaObs) 
summary(RichPC1)# Significant coefficient
## 
## Call:
## lm(formula = rich ~ PC1 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -74.332 -14.939   4.194  19.133  48.387 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  468.360     12.361  37.890   <2e-16 ***
## PC1            2.629      2.721   0.966   0.3366    
## SpeciesIp     -5.247      6.422  -0.817   0.4162    
## TRTInter     -14.115      8.160  -1.730   0.0871 .  
## Block2       -20.098     23.605  -0.851   0.3968    
## Block3        -4.476     24.228  -0.185   0.8539    
## Block4        -7.361      6.928  -1.063   0.2908    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 27.68 on 89 degrees of freedom
## Multiple R-squared:  0.1424, Adjusted R-squared:  0.08462 
## F-statistic: 2.464 on 6 and 89 DF,  p-value: 0.0299
# Adjust p-value for multiple comparisons (1 for each PC used to test)
p.adjust((summary(RichPC1)$coefficients[2,4]), method = "bonferroni", n = 4) # still significant, corrected p-value:
## [1] 1
# 0.01158722

EvenPC1=lm(even~PC1+Species+TRT+Block,RootAlphaObs) 
summary(EvenPC1)# Significant coefficient
## 
## Call:
## lm(formula = even ~ PC1 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -8.166e-04 -2.610e-04  1.249e-05  2.338e-04  1.238e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.015e-02  1.765e-04  57.516   <2e-16 ***
## PC1         -1.933e-05  3.887e-05  -0.497    0.620    
## SpeciesIp    1.180e-04  9.172e-05   1.287    0.201    
## TRTInter     1.512e-04  1.165e-04   1.297    0.198    
## Block2       1.516e-04  3.371e-04   0.450    0.654    
## Block3      -2.070e-04  3.460e-04  -0.598    0.551    
## Block4      -4.765e-05  9.894e-05  -0.482    0.631    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0003954 on 89 degrees of freedom
## Multiple R-squared:  0.1476, Adjusted R-squared:  0.0901 
## F-statistic: 2.568 on 6 and 89 DF,  p-value: 0.02432
    # Adjust p-value for multiple comparisons (1 for each PC used to test)
    p.adjust((summary(EvenPC1)$coefficients[2,4]), method = "bonferroni", n = 4) # still significant, corrected p-value:
## [1] 1
    # 0.02191386

SimpPC2=lm(sim~PC2+Species+TRT+Block,RootAlphaObs) 
summary(SimpPC2) 
## 
## Call:
## lm(formula = sim ~ PC2 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.028163 -0.004043  0.001313  0.005830  0.013279 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.736e-01  3.013e-03 323.175   <2e-16 ***
## PC2         -7.810e-04  5.118e-04  -1.526    0.131    
## SpeciesIp   -8.854e-05  1.798e-03  -0.049    0.961    
## TRTInter    -2.285e-03  2.357e-03  -0.969    0.335    
## Block2       6.113e-04  3.135e-03   0.195    0.846    
## Block3       4.825e-04  2.426e-03   0.199    0.843    
## Block4      -1.923e-03  2.492e-03  -0.772    0.442    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007889 on 89 degrees of freedom
## Multiple R-squared:  0.0989, Adjusted R-squared:  0.03815 
## F-statistic: 1.628 on 6 and 89 DF,  p-value: 0.1487
SimpInvPC2=lm(InvSimp~PC2+Species+TRT+Block,RootAlphaObs)
summary(SimpInvPC2) 
## 
## Call:
## lm(formula = InvSimp ~ PC2 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.1610  -6.3592   0.0581   5.8878  26.1557 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  38.9405     3.4545  11.272   <2e-16 ***
## PC2          -0.6367     0.5869  -1.085    0.281    
## SpeciesIp     0.7634     2.0611   0.370    0.712    
## TRTInter     -1.5637     2.7031  -0.578    0.564    
## Block2        0.6192     3.5942   0.172    0.864    
## Block3        0.7374     2.7818   0.265    0.792    
## Block4       -3.1693     2.8575  -1.109    0.270    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.046 on 89 degrees of freedom
## Multiple R-squared:  0.08677,    Adjusted R-squared:  0.02521 
## F-statistic: 1.409 on 6 and 89 DF,  p-value: 0.2198
RichPC2=lm(rich~PC2+Species+TRT+Block,RootAlphaObs) 
summary(RichPC2) # Significant coefficient
## 
## Call:
## lm(formula = rich ~ PC2 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -75.991 -15.616   2.075  19.857  46.962 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 448.8092    10.1991  44.005  < 2e-16 ***
## PC2          -4.7872     1.7326  -2.763  0.00696 ** 
## SpeciesIp    -4.7202     6.0851  -0.776  0.43998    
## TRTInter     -8.8563     7.9807  -1.110  0.27011    
## Block2        0.7606    10.6114   0.072  0.94302    
## Block3       27.3263     8.2128   3.327  0.00128 ** 
## Block4        6.1108     8.4363   0.724  0.47075    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 26.71 on 89 degrees of freedom
## Multiple R-squared:  0.2019, Adjusted R-squared:  0.1481 
## F-statistic: 3.752 on 6 and 89 DF,  p-value: 0.002246
    # Adjust p-value for multiple comparisons (1 for each PC used to test)
    p.adjust((summary(RichPC2)$coefficients[2,4]), method = "bonferroni", n = 4) # still significant, corrected p-value:
## [1] 0.02783753
    # 0.04698757


EvenPC2=lm(even~PC2+Species+TRT+Block,RootAlphaObs) 
summary(EvenPC2) # Significant coefficient
## 
## Call:
## lm(formula = even ~ PC2 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -7.710e-04 -2.357e-04 -2.286e-05  2.430e-04  1.249e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.036e-02  1.467e-04  70.584  < 2e-16 ***
## PC2          5.855e-05  2.492e-05   2.349   0.0210 *  
## SpeciesIp    1.174e-04  8.754e-05   1.341   0.1832    
## TRTInter     9.117e-05  1.148e-04   0.794   0.4292    
## Block2      -5.041e-06  1.526e-04  -0.033   0.9737    
## Block3      -4.877e-04  1.181e-04  -4.128 8.23e-05 ***
## Block4      -2.175e-04  1.214e-04  -1.792   0.0765 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0003842 on 89 degrees of freedom
## Multiple R-squared:  0.1951, Adjusted R-squared:  0.1408 
## F-statistic: 3.595 on 6 and 89 DF,  p-value: 0.003081
    # Adjust p-value for multiple comparisons (1 for each PC used to test)
    p.adjust((summary(EvenPC2)$coefficients[2,4]), method = "bonferroni", n = 4) # Not significant, corrected p-value:
## [1] 0.08414438
    # 0.1492003

### PC3
SimpPC3=lm(sim~PC3+Species+TRT+Block,RootAlphaObs) 
summary(SimpPC3) 
## 
## Call:
## lm(formula = sim ~ PC3 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.029375 -0.003550  0.001677  0.005369  0.011926 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.752e-01  2.789e-03 349.633   <2e-16 ***
## PC3          5.220e-04  5.981e-04   0.873   0.3851    
## SpeciesIp    2.978e-05  1.812e-03   0.016   0.9869    
## TRTInter    -2.606e-03  2.374e-03  -1.098   0.2753    
## Block2       9.475e-04  3.202e-03   0.296   0.7680    
## Block3      -1.052e-03  2.217e-03  -0.474   0.6364    
## Block4      -4.386e-03  1.970e-03  -2.226   0.0285 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007958 on 89 degrees of freedom
## Multiple R-squared:  0.08317,    Adjusted R-squared:  0.02136 
## F-statistic: 1.346 on 6 and 89 DF,  p-value: 0.2456
SimpInvPC3=lm(InvSimp~PC3+Species+TRT+Block,RootAlphaObs) 
summary(SimpInvPC3) 
## 
## Call:
## lm(formula = InvSimp ~ PC3 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -18.750  -5.725   0.898   5.296  24.783 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  40.1016     3.1796  12.612   <2e-16 ***
## PC3           0.5575     0.6818   0.818   0.4157    
## SpeciesIp     0.8623     2.0654   0.418   0.6773    
## TRTInter     -1.7262     2.7059  -0.638   0.5252    
## Block2        1.0062     3.6504   0.276   0.7835    
## Block3       -0.5047     2.5274  -0.200   0.8422    
## Block4       -5.2006     2.2461  -2.315   0.0229 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.072 on 89 degrees of freedom
## Multiple R-squared:  0.0816, Adjusted R-squared:  0.01968 
## F-statistic: 1.318 on 6 and 89 DF,  p-value: 0.2575
RichPC3=lm(rich~PC3+Species+TRT+Block,RootAlphaObs) 
summary(RichPC3)
## 
## Call:
## lm(formula = rich ~ PC3 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -72.850 -13.323   4.371  16.234  51.760 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  458.894      9.679  47.413   <2e-16 ***
## PC3            2.450      2.076   1.180   0.2410    
## SpeciesIp     -4.009      6.287  -0.638   0.5253    
## TRTInter     -11.388      8.237  -1.383   0.1703    
## Block2         2.179     11.112   0.196   0.8450    
## Block3        17.874      7.693   2.323   0.0224 *  
## Block4        -8.845      6.837  -1.294   0.1991    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 27.61 on 89 degrees of freedom
## Multiple R-squared:  0.1468, Adjusted R-squared:  0.08927 
## F-statistic: 2.552 on 6 and 89 DF,  p-value: 0.02509
EvenPC3=lm(even~PC3+Species+TRT+Block,RootAlphaObs) 
summary(EvenPC3)
## 
## Call:
## lm(formula = even ~ PC3 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -7.938e-04 -2.616e-04  4.780e-06  2.184e-04  1.217e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.023e-02  1.383e-04  73.966  < 2e-16 ***
## PC3         -2.374e-05  2.965e-05  -0.801  0.42548    
## SpeciesIp    1.088e-04  8.982e-05   1.212  0.22883    
## TRTInter     1.268e-04  1.177e-04   1.078  0.28413    
## Block2      -1.706e-05  1.587e-04  -0.107  0.91464    
## Block3      -3.717e-04  1.099e-04  -3.382  0.00107 ** 
## Block4      -3.570e-05  9.768e-05  -0.365  0.71564    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0003945 on 89 degrees of freedom
## Multiple R-squared:  0.1513, Adjusted R-squared:  0.09409 
## F-statistic: 2.645 on 6 and 89 DF,  p-value: 0.02087
### PC4
SimpPC4=lm(sim~PC4+Species+TRT+Block,RootAlphaObs) 
summary(SimpPC4) # Significant coefficient
## 
## Call:
## lm(formula = sim ~ PC4 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.023817 -0.004794  0.001242  0.005232  0.014173 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.9759837  0.0026241 371.935  < 2e-16 ***
## PC4          0.0022233  0.0007098   3.132  0.00235 ** 
## SpeciesIp    0.0011200  0.0017621   0.636  0.52665    
## TRTInter    -0.0025128  0.0022268  -1.128  0.26217    
## Block2      -0.0012309  0.0030630  -0.402  0.68876    
## Block3      -0.0020022  0.0021329  -0.939  0.35041    
## Block4      -0.0059073  0.0019448  -3.038  0.00313 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007584 on 89 degrees of freedom
## Multiple R-squared:  0.1671, Adjusted R-squared:  0.111 
## F-statistic: 2.977 on 6 and 89 DF,  p-value: 0.01072
    # Adjust p-value for multiple comparisons (1 for each PC used to test)
    p.adjust((summary(SimpPC4)$coefficients[2,4]), method = "bonferroni", n = 4) # still significant, corrected p-value:
## [1] 0.009386743
    # 0.00834712

SimpInvPC4=lm(InvSimp~PC4+Species+TRT+Block,RootAlphaObs) 
summary(SimpInvPC4)  # Significant coefficient
## 
## Call:
## lm(formula = InvSimp ~ PC4 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.2849  -7.2012   0.6678   5.0565  26.9767 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  40.8792     3.0527  13.391  < 2e-16 ***
## PC4           1.9858     0.8257   2.405  0.01825 *  
## SpeciesIp     1.8344     2.0499   0.895  0.37329    
## TRTInter     -1.7118     2.5906  -0.661  0.51047    
## Block2       -1.0175     3.5633  -0.286  0.77590    
## Block3       -1.3595     2.4813  -0.548  0.58512    
## Block4       -6.5430     2.2625  -2.892  0.00481 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.823 on 89 degrees of freedom
## Multiple R-squared:  0.1312, Adjusted R-squared:  0.07258 
## F-statistic: 2.239 on 6 and 89 DF,  p-value: 0.04652
  # Adjust p-value for multiple comparisons (1 for each PC used to test)
      p.adjust((summary(SimpInvPC4)$coefficients[2,4]), method = "bonferroni", n = 4) # marginally significant, corrected p-value:
## [1] 0.07299534
      # 0.07073862

RichPC4=lm(rich~PC4+Species+TRT+Block,RootAlphaObs) 
summary(RichPC4)
## 
## Call:
## lm(formula = rich ~ PC4 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -76.083 -13.070   5.103  18.490  50.646 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  461.363      9.543  48.345   <2e-16 ***
## PC4            3.260      2.581   1.263   0.2099    
## SpeciesIp     -2.442      6.408  -0.381   0.7041    
## TRTInter     -12.517      8.098  -1.546   0.1257    
## Block2        -2.457     11.139  -0.221   0.8260    
## Block3        16.370      7.757   2.110   0.0376 *  
## Block4       -10.769      7.073  -1.523   0.1314    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 27.58 on 89 degrees of freedom
## Multiple R-squared:  0.1487, Adjusted R-squared:  0.0913 
## F-statistic: 2.591 on 6 and 89 DF,  p-value: 0.02322
EvenPC4=lm(even~PC4+Species+TRT+Block,RootAlphaObs) 
summary(EvenPC4)
## 
## Call:
## lm(formula = even ~ PC4 + Species + TRT + Block, data = RootAlphaObs)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -8.262e-04 -2.521e-04 -6.220e-06  2.183e-04  1.201e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.021e-02  1.367e-04  74.719  < 2e-16 ***
## PC4          2.285e-05  3.697e-05   0.618 0.538201    
## SpeciesIp    1.206e-04  9.179e-05   1.314 0.192340    
## TRTInter     1.496e-04  1.160e-04   1.290 0.200393    
## Block2      -1.454e-05  1.596e-04  -0.091 0.927613    
## Block3      -3.795e-04  1.111e-04  -3.416 0.000959 ***
## Block4      -5.663e-05  1.013e-04  -0.559 0.577533    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0003951 on 89 degrees of freedom
## Multiple R-squared:  0.1488, Adjusted R-squared:  0.09147 
## F-statistic: 2.594 on 6 and 89 DF,  p-value: 0.02308

Within species (root traits and alphadiv)

library(multcomp)

#summary(glht(SimpInvPC1, mcp(rank="Tukey")))

#################################################################
##################### SUBSET for I.purpurea #####################
#################################################################


RootAlphaPurp=droplevels(RootAlphaObs%>%filter(Species=="Ip"))
RootAlphaPurp$Comp=sub(".*\\-","",RootAlphaPurp$Combos)

SimpPC1=lm(sim~TRT+Block+PC1,RootAlphaPurp) 
summary(SimpPC1)
## 
## Call:
## lm(formula = sim ~ TRT + Block + PC1, data = RootAlphaPurp)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.027297 -0.003731  0.001626  0.005703  0.011295 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.977953   0.003829 255.423   <2e-16 ***
## TRTInter    -0.004158   0.002444  -1.701    0.095 .  
## Block2      -0.005971   0.010260  -0.582    0.563    
## Block3      -0.010164   0.010768  -0.944    0.350    
## Block4      -0.002088   0.002608  -0.801    0.427    
## PC1          0.001497   0.001244   1.203    0.235    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.008101 on 51 degrees of freedom
## Multiple R-squared:  0.1349, Adjusted R-squared:  0.05008 
## F-statistic:  1.59 on 5 and 51 DF,  p-value: 0.1796
anova(SimpPC1) # Significant Competitor effect
## Analysis of Variance Table
## 
## Response: sim
##           Df    Sum Sq    Mean Sq F value Pr(>F)
## TRT        1 0.0001038 1.0383e-04  1.5821 0.2142
## Block      3 0.0003231 1.0771e-04  1.6412 0.1914
## PC1        1 0.0000949 9.4924e-05  1.4464 0.2347
## Residuals 51 0.0033471 6.5630e-05
car::Anova(SimpPC1)
## Anova Table (Type II tests)
## 
## Response: sim
##              Sum Sq Df F value  Pr(>F)  
## TRT       0.0001899  1  2.8936 0.09502 .
## Block     0.0001317  3  0.6689 0.57502  
## PC1       0.0000949  1  1.4464 0.23467  
## Residuals 0.0033471 51                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
SimpInvPC1=lm(InvSimp~PC1+Comp+TRT+Block,RootAlphaPurp) 
anova(SimpInvPC1) # Significant PC1 effect only, no Comp or Comp by PC1 effect
## Analysis of Variance Table
## 
## Response: InvSimp
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## PC1        1  446.3  446.32  5.4546 0.02374 *
## Comp       4  575.9  143.98  1.7596 0.15252  
## Block      3  127.2   42.39  0.5181 0.67183  
## Residuals 48 3927.6   81.83                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RichPC1=lm(rich~TRT+Block+PC1,RootAlphaPurp) 
anova(RichPC1) 
## Analysis of Variance Table
## 
## Response: rich
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## TRT        1   1794 1793.66  1.9903 0.16438  
## Block      3   7423 2474.18  2.7454 0.05244 .
## PC1        1   1395 1395.16  1.5481 0.21910  
## Residuals 51  45962  901.21                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(RichPC1 )
## 
## Call:
## lm(formula = rich ~ TRT + Block + PC1, data = RootAlphaPurp)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -66.678 -15.781   3.311  19.513  52.108 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  467.490     14.188  32.950   <2e-16 ***
## TRTInter     -17.028      9.057  -1.880   0.0658 .  
## Block2       -28.723     38.021  -0.755   0.4535    
## Block3       -22.647     39.902  -0.568   0.5728    
## Block4        -1.931      9.663  -0.200   0.8424    
## PC1            5.738      4.611   1.244   0.2191    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 30.02 on 51 degrees of freedom
## Multiple R-squared:  0.1876, Adjusted R-squared:  0.1079 
## F-statistic: 2.355 on 5 and 51 DF,  p-value: 0.05347
car::Anova(lm(sim~TRT+Block+PC2*TRT,RootAlphaPurp),type="III") # No interaction effect
## Anova Table (Type III tests)
## 
## Response: sim
##             Sum Sq Df    F value Pr(>F)    
## (Intercept) 6.6130  1 1.0031e+05 <2e-16 ***
## TRT         0.0001  1 1.7134e+00 0.1965    
## Block       0.0002  3 1.0333e+00 0.3859    
## PC2         0.0000  1 5.7400e-02 0.8116    
## TRT:PC2     0.0000  1 4.0090e-01 0.5295    
## Residuals   0.0033 50                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
SimpPC2=lm(sim~TRT+Block+PC2,RootAlphaPurp) 
summary(SimpPC2) # NS
## 
## Call:
## lm(formula = sim ~ TRT + Block + PC2, data = RootAlphaPurp)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.027720 -0.004143  0.001226  0.005538  0.012149 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.722e-01  2.897e-03 335.574   <2e-16 ***
## TRTInter    -2.860e-03  2.452e-03  -1.166    0.249    
## Block2       5.727e-03  4.583e-03   1.250    0.217    
## Block3       3.611e-03  3.187e-03   1.133    0.262    
## Block4      -8.435e-05  3.198e-03  -0.026    0.979    
## PC2         -8.487e-04  6.270e-04  -1.354    0.182    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.008072 on 51 degrees of freedom
## Multiple R-squared:  0.1412, Adjusted R-squared:  0.05702 
## F-statistic: 1.677 on 5 and 51 DF,  p-value: 0.157
# ANCOVA

car::Anova(lm(sim~TRT+Block+PC2*TRT,RootAlphaPurp),type="III") # No interaction effect
## Anova Table (Type III tests)
## 
## Response: sim
##             Sum Sq Df    F value Pr(>F)    
## (Intercept) 6.6130  1 1.0031e+05 <2e-16 ***
## TRT         0.0001  1 1.7134e+00 0.1965    
## Block       0.0002  3 1.0333e+00 0.3859    
## PC2         0.0000  1 5.7400e-02 0.8116    
## TRT:PC2     0.0000  1 4.0090e-01 0.5295    
## Residuals   0.0033 50                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
SimpInvPC2=lm(InvSimp~TRT+Block+PC2+Block,RootAlphaPurp) 
anova(SimpInvPC2) # NS
## Analysis of Variance Table
## 
## Response: InvSimp
##           Df Sum Sq Mean Sq F value Pr(>F)
## TRT        1   50.6  50.554  0.5864 0.4473
## Block      3  555.2 185.070  2.1468 0.1058
## PC2        1   74.7  74.736  0.8669 0.3562
## Residuals 51 4396.5  86.206
# ANCOVA
car::Anova(lm(InvSimp~TRT+Block+PC2*TRT,RootAlphaPurp),type="III") # No interaction effect
## Anova Table (Type III tests)
## 
## Response: InvSimp
##              Sum Sq Df  F value    Pr(>F)    
## (Intercept) 10586.5  1 121.6277 5.386e-15 ***
## TRT            90.0  1   1.0345    0.3140    
## Block         405.0  3   1.5510    0.2129    
## PC2             0.4  1   0.0042    0.9483    
## TRT:PC2        44.5  1   0.5115    0.4778    
## Residuals    4352.0 50                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RichPC2=lm(rich~TRT+Block+PC2,RootAlphaPurp) 
anova(RichPC2) # Significant coefficient SUPER small effect size
## Analysis of Variance Table
## 
## Response: rich
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## TRT        1   1794  1793.7  2.1642 0.14741  
## Block      3   7423  2474.2  2.9853 0.03966 *
## PC2        1   5088  5087.8  6.1388 0.01658 *
## Residuals 51  42269   828.8                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
EvenPC2=lm(even~TRT+Block+PC2,RootAlphaPurp) 
anova(EvenPC2) # Significant mean Evenness effect--should Check this out it is suspect
## Analysis of Variance Table
## 
## Response: even
##           Df     Sum Sq    Mean Sq F value  Pr(>F)  
## TRT        1 1.9390e-07 1.9387e-07  1.0898 0.30145  
## Block      3 1.1554e-06 3.8512e-07  2.1648 0.10354  
## PC2        1 8.7980e-07 8.7979e-07  4.9454 0.03062 *
## Residuals 51 9.0729e-06 1.7790e-07                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
### PC3
SimpPC3=lm(sim~TRT+Block+PC3,RootAlphaPurp) 
anova(SimpPC3) # NS
## Analysis of Variance Table
## 
## Response: sim
##           Df    Sum Sq    Mean Sq F value Pr(>F)
## TRT        1 0.0001038 1.0383e-04  1.5905 0.2130
## Block      3 0.0003231 1.0771e-04  1.6499 0.1895
## PC3        1 0.0001126 1.1260e-04  1.7247 0.1950
## Residuals 51 0.0033295 6.5283e-05
SimpInvPC3=lm(InvSimp~TRT+Block+PC3,RootAlphaPurp) 
anova(SimpInvPC3) # NS
## Analysis of Variance Table
## 
## Response: InvSimp
##           Df Sum Sq Mean Sq F value Pr(>F)
## TRT        1   50.6  50.554  0.5881 0.4467
## Block      3  555.2 185.070  2.1531 0.1050
## PC3        1   87.5  87.460  1.0175 0.3179
## Residuals 51 4383.8  85.957
RichPC3=lm(rich~TRT+Block+PC3,RootAlphaPurp) 
anova(RichPC3)
## Analysis of Variance Table
## 
## Response: rich
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## TRT        1   1794 1793.66  1.9807 0.16538  
## Block      3   7423 2474.18  2.7322 0.05325 .
## PC3        1   1173 1172.65  1.2949 0.26046  
## Residuals 51  46184  905.57                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
EvenPC3=lm(even~TRT+Block+PC3,RootAlphaPurp) 
summary(EvenPC3)
## 
## Call:
## lm(formula = even ~ TRT + Block + PC3, data = RootAlphaPurp)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -8.239e-04 -2.849e-04 -3.885e-05  2.306e-04  1.201e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.035e-02  1.348e-04  76.782   <2e-16 ***
## TRTInter     1.401e-04  1.337e-04   1.047   0.3000    
## Block2      -1.288e-04  2.523e-04  -0.511   0.6118    
## Block3      -3.951e-04  1.658e-04  -2.383   0.0209 *  
## Block4      -6.959e-05  1.394e-04  -0.499   0.6197    
## PC3         -2.215e-05  4.087e-05  -0.542   0.5902    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0004405 on 51 degrees of freedom
## Multiple R-squared:  0.1244, Adjusted R-squared:  0.03858 
## F-statistic: 1.449 on 5 and 51 DF,  p-value: 0.2228
anova(EvenPC3)
## Analysis of Variance Table
## 
## Response: even
##           Df     Sum Sq    Mean Sq F value Pr(>F)
## TRT        1 1.9390e-07 1.9387e-07  0.9992 0.3222
## Block      3 1.1554e-06 3.8512e-07  1.9848 0.1279
## PC3        1 5.7000e-08 5.6990e-08  0.2937 0.5902
## Residuals 51 9.8957e-06 1.9403e-07
### PC4
SimpPC4=lm(sim~TRT+Block+PC4,RootAlphaPurp%>%filter(sim>0.94)) 
summary(SimpPC4) # Significant
## 
## Call:
## lm(formula = sim ~ TRT + Block + PC4, data = RootAlphaPurp %>% 
##     filter(sim > 0.94))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.017691 -0.003427  0.001411  0.004308  0.011779 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.9744883  0.0022109 440.770   <2e-16 ***
## TRTInter    -0.0025833  0.0020766  -1.244    0.219    
## Block2       0.0035283  0.0041907   0.842    0.404    
## Block3       0.0016194  0.0026821   0.604    0.549    
## Block4      -0.0021490  0.0024082  -0.892    0.376    
## PC4          0.0007738  0.0009356   0.827    0.412    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006953 on 50 degrees of freedom
## Multiple R-squared:  0.09791,    Adjusted R-squared:  0.007699 
## F-statistic: 1.085 on 5 and 50 DF,  p-value: 0.38
anova(SimpPC4)
## Analysis of Variance Table
## 
## Response: sim
##           Df     Sum Sq    Mean Sq F value Pr(>F)
## TRT        1 0.00005203 5.2027e-05  1.0761 0.3046
## Block      3 0.00017726 5.9087e-05  1.2222 0.3114
## PC4        1 0.00003307 3.3071e-05  0.6841 0.4121
## Residuals 50 0.00241730 4.8346e-05
SimpInvPC4=lm(InvSimp~TRT+Block+PC4,RootAlphaPurp) 
summary(SimpInvPC4)  # Marginal InvSimp significant
## 
## Call:
## lm(formula = InvSimp ~ TRT + Block + PC4, data = RootAlphaPurp)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -17.2490  -6.8413   0.7427   4.4331  25.1870 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   41.447      2.799  14.810   <2e-16 ***
## TRTInter      -2.242      2.693  -0.833   0.4090    
## Block2         2.810      5.370   0.523   0.6031    
## Block3         2.325      3.460   0.672   0.5046    
## Block4        -4.976      2.980  -1.670   0.1011    
## PC4            2.083      1.054   1.977   0.0534 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.024 on 51 degrees of freedom
## Multiple R-squared:  0.182,  Adjusted R-squared:  0.1018 
## F-statistic:  2.27 on 5 and 51 DF,  p-value: 0.06129
anova(SimpInvPC4)
## Analysis of Variance Table
## 
## Response: InvSimp
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## TRT        1   50.6   50.55  0.6208 0.43438  
## Block      3  555.2  185.07  2.2728 0.09121 .
## PC4        1  318.4  318.40  3.9102 0.05341 .
## Residuals 51 4152.9   81.43                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RichPC4=lm(rich~TRT+Block+PC4,RootAlphaPurp) 
summary(RichPC4) # NS
## 
## Call:
## lm(formula = rich ~ TRT + Block + PC4, data = RootAlphaPurp)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -71.495 -11.318   6.298  18.927  54.578 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  455.804      9.398  48.502   <2e-16 ***
## TRTInter     -14.045      9.044  -1.553   0.1266    
## Block2         9.298     18.033   0.516   0.6083    
## Block3        23.133     11.620   1.991   0.0519 .  
## Block4        -6.509     10.007  -0.650   0.5183    
## PC4            2.686      3.538   0.759   0.4512    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 30.3 on 51 degrees of freedom
## Multiple R-squared:  0.1723, Adjusted R-squared:  0.09111 
## F-statistic: 2.123 on 5 and 51 DF,  p-value: 0.07759
anova(RichPC4)
## Analysis of Variance Table
## 
## Response: rich
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## TRT        1   1794 1793.66  1.9535 0.16826  
## Block      3   7423 2474.18  2.6946 0.05564 .
## PC4        1    529  529.24  0.5764 0.45122  
## Residuals 51  46827  918.18                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
EvenPC4=lm(even~TRT+Block+PC4,RootAlphaPurp) 
summary(EvenPC4)
## 
## Call:
## lm(formula = even ~ TRT + Block + PC4, data = RootAlphaPurp)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -8.251e-04 -2.680e-04 -5.078e-05  2.324e-04  1.146e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.037e-02  1.360e-04  76.251   <2e-16 ***
## TRTInter     1.700e-04  1.309e-04   1.299   0.1998    
## Block2      -1.779e-04  2.609e-04  -0.682   0.4986    
## Block3      -4.182e-04  1.681e-04  -2.487   0.0162 *  
## Block4      -1.117e-04  1.448e-04  -0.772   0.4439    
## PC4          4.470e-05  5.119e-05   0.873   0.3867    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0004385 on 51 degrees of freedom
## Multiple R-squared:  0.1324, Adjusted R-squared:  0.04729 
## F-statistic: 1.556 on 5 and 51 DF,  p-value: 0.1894
anova(EvenPC4)
## Analysis of Variance Table
## 
## Response: even
##           Df     Sum Sq    Mean Sq F value Pr(>F)
## TRT        1 1.9390e-07 1.9387e-07  1.0083 0.3201
## Block      3 1.1554e-06 3.8512e-07  2.0030 0.1252
## PC4        1 1.4660e-07 1.4660e-07  0.7624 0.3867
## Residuals 51 9.8061e-06 1.9228e-07

Plotting significant linear associations

# Richness and root architecture
P2.rich=ggplot()+
  geom_point(data=RootAlphaPurp,aes(PC2,rich),alpha=0.5,size=5)+
  geom_smooth(data=RootAlphaPurp,method="lm",aes(PC2,rich),fullrange=TRUE)+
  theme_classic()+
  ylab("Richness")+
  xlab("")+
  Tx2
#+ 
  #annotate("text", x = -1, y = 500, label = "paste(italic(R) ^ 2, \" = 0.15\")", parse = TRUE,hjust=0,size=5)+ 
 # annotate("text", x = -1, y = 490, label = "paste(italic(B), \" = -4.65 +/-1.81\")", parse = TRUE,hjust=0,size=5)+
 # annotate("text", x = -1, y = 480, label = "paste(italic(P), \" = 0.01\")", parse = TRUE,hjust=0,size=5)

# Evenness and root architecture
P2.even=ggplot()+
  geom_point(data=RootAlphaPurp,aes(PC2,even),alpha=0.5,size=5)+
  geom_smooth(data=RootAlphaPurp,method="lm",aes(PC2,even),fullrange=TRUE)+
  theme_classic()+
  ylab("Evenness")+
  xlab("")+
  Tx2#+ 
  #annotate("text", x = -4.5, y = .0114, label = "paste(italic(R) ^ 2, \" = 0.12\")", parse = TRUE,hjust=0,size=5)+ 
#  annotate("text", x = -4.5, y = .0112, label = "paste(italic(B), \" = -7.29E-5 +/-3.28E-5\")", parse = TRUE,hjust=0,size=5)+
 # annotate("text", x = -4.5, y =.011, label = "paste(italic(P), \" = 0.04\")", parse = TRUE,hjust=0,size=5)


# Root morphology on species diversity Simpson metric

P4.Sim<-ggplot()+
  geom_point(data=RootAlphaPurp,aes(PC4,sim),alpha=0.5,size=5)+
  geom_smooth(data=RootAlphaPurp,method="lm",aes(PC4,sim),fullrange=TRUE)+
  theme_classic()+
  ylab("Simpson")+
  xlab("")+
  Tx2#+
  #annotate("text", x = -5, y = .988, label = "paste(italic(R) ^ 2, \" = 0.18\")", parse = TRUE,hjust=0,size=5)+ 
  #annotate("text", x = -5, y = .985, label = "paste(italic(B), \" = 2.22E-4 +/-6.99E-4\")", parse = TRUE,hjust=0,size=5)+
 # annotate("text", x =-5, y = .982, label = "paste(italic(P), \" < 0.01\")", parse = TRUE,hjust=0,size=5)


P4.simIn=ggplot()+
  geom_point(data=RootAlphaPurp,aes(PC4,InvSimp),alpha=0.5,size=5)+
  geom_smooth(data=RootAlphaPurp,method="lm",aes(PC4,InvSimp),fullrange=TRUE)+
  theme_classic()+
  ylab("Inverse Simpson")+
  xlab("")+
  Tx2#+
 # annotate("text", x = -5, y = 60, label = "paste(italic(R) ^ 2, \" = 0.12\")", parse = TRUE,hjust=0,size=5)+ 
 # annotate("text", x = -5, y = 57, label = "paste(italic(B), \" = 2.08 +/-1.05\")", parse = TRUE,hjust=0,size=5)+
 # annotate("text", x =-5, y = 54, label = "paste(italic(P), \" = 0.02\")", parse = TRUE,hjust=0,size=5)

Linear mixed models

### Simpson
SimpLMM=lmer(sim~TRT+Block+(1|ML),alpha%>%filter(Species=="Ip")) 
## boundary (singular) fit: see ?isSingular
anova(SimpLMM)
## Type III Analysis of Variance Table with Satterthwaite's method
##           Sum Sq    Mean Sq NumDF DenDF F value  Pr(>F)  
## TRT   0.00004080 4.0802e-05     1    95  0.6782 0.41228  
## Block 0.00051675 1.7225e-04     3    95  2.8629 0.04084 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(SimpLMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## sim ~ TRT + Block + (1 | ML)
##          npar logLik    AIC LRT Df Pr(>Chisq)
## <none>      7  318.9 -623.8                  
## (1 | ML)    6  318.9 -625.8   0  1          1
### Inverse Simpson
SimpInvLMM=lmer(InvSimp~TRT+Block+(1|ML),alpha%>%filter(Species=="Ip")) 
## boundary (singular) fit: see ?isSingular
anova(SimpInvLMM)
## Type III Analysis of Variance Table with Satterthwaite's method
##       Sum Sq Mean Sq NumDF DenDF F value   Pr(>F)   
## TRT        3    3.00     1    95  0.0349 0.852131   
## Block   1064  354.66     3    95  4.1296 0.008463 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(SimpInvLMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## InvSimp ~ TRT + Block + (1 | ML)
##          npar  logLik    AIC        LRT Df Pr(>Chisq)
## <none>      7 -354.24 722.48                         
## (1 | ML)    6 -354.24 720.48 1.1369e-13  1          1
### Inverse Simpson
RichLMM=lmer(rich~TRT+Block+(1|ML),alpha%>%filter(Species=="Ip")) 
anova(RichLMM)
## Type III Analysis of Variance Table with Satterthwaite's method
##        Sum Sq Mean Sq NumDF  DenDF F value   Pr(>F)   
## TRT    1254.9  1254.9     1 90.695  1.3836 0.242565   
## Block 15233.7  5077.9     3 92.147  5.5989 0.001428 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(RichLMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## rich ~ TRT + Block + (1 | ML)
##          npar  logLik    AIC     LRT Df Pr(>Chisq)
## <none>      7 -467.16 948.32                      
## (1 | ML)    6 -467.29 946.58 0.26321  1     0.6079
# Bray curtis metric now


Ax1LMM=lmer(Axis.1~Species+TRT+Block+(1|ML),physeq.pcoa.df)
## boundary (singular) fit: see ?isSingular
anova(Ax1LMM)
## Type III Analysis of Variance Table with Satterthwaite's method
##           Sum Sq  Mean Sq NumDF DenDF F value    Pr(>F)    
## Species 0.000847 0.000847     1   167  0.1281    0.7208    
## TRT     0.005399 0.005399     1   167  0.8164    0.3676    
## Block   0.217604 0.072535     3   167 10.9674 1.302e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(Ax1LMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## Axis.1 ~ Species + TRT + Block + (1 | ML)
##          npar logLik     AIC        LRT Df Pr(>Chisq)
## <none>      8 171.21 -326.41                         
## (1 | ML)    7 171.21 -328.41 1.7053e-13  1          1
Ax2LMM=lmer(Axis.2~Species+TRT+Block+(1|ML),physeq.pcoa.df)
## boundary (singular) fit: see ?isSingular
anova(Ax2LMM) # Significant species diffeences in axis 2
## Type III Analysis of Variance Table with Satterthwaite's method
##            Sum Sq   Mean Sq NumDF DenDF F value  Pr(>F)  
## Species 0.0227878 0.0227878     1   167  4.7831 0.03013 *
## TRT     0.0000000 0.0000000     1   167  0.0000 0.99911  
## Block   0.0092565 0.0030855     3   167  0.6476 0.58549  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(Ax2LMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## Axis.2 ~ Species + TRT + Block + (1 | ML)
##          npar logLik     AIC LRT Df Pr(>Chisq)
## <none>      8 198.59 -381.18                  
## (1 | ML)    7 198.59 -383.18   0  1          1
Ax3LMM=lmer(Axis.3~Species+TRT+Block+(1|ML),physeq.pcoa.df)
## boundary (singular) fit: see ?isSingular
anova(Ax3LMM) 
## Type III Analysis of Variance Table with Satterthwaite's method
##            Sum Sq   Mean Sq NumDF DenDF F value  Pr(>F)  
## Species 0.0006216 0.0006216     1   167  0.1754 0.67590  
## TRT     0.0040354 0.0040354     1   167  1.1387 0.28746  
## Block   0.0256465 0.0085488     3   167  2.4123 0.06861 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(Ax3LMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## Axis.3 ~ Species + TRT + Block + (1 | ML)
##          npar logLik     AIC LRT Df Pr(>Chisq)
## <none>      8  223.3 -430.61                  
## (1 | ML)    7  223.3 -432.61   0  1          1
Ax4LMM=lmer(Axis.4~Species+TRT+Block+(1|ML),physeq.pcoa.df)
## boundary (singular) fit: see ?isSingular
anova(Ax4LMM) # Marginal species differences
## Type III Analysis of Variance Table with Satterthwaite's method
##           Sum Sq  Mean Sq NumDF DenDF F value    Pr(>F)    
## Species 0.000429 0.000429     1   167  0.2046    0.6516    
## TRT     0.004337 0.004337     1   167  2.0670    0.1524    
## Block   0.107444 0.035815     3   167 17.0687 1.023e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(Ax4LMM)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## Axis.4 ~ Species + TRT + Block + (1 | ML)
##          npar logLik     AIC LRT Df Pr(>Chisq)
## <none>      8 267.06 -518.13                  
## (1 | ML)    7 267.06 -520.13   0  1          1
Fitness=read.csv("~/Google Drive File Stream/My Drive/Field_2018/Field_2018_Rcode/CharacterDisplacementRootTraits/CleanData/FitPA4.csv")

library(dplyr)
# Calculate relative fitness
  # First calculate mean seed number by species and treatment---note* we only have seed output of I. purpurea
MeanSeedNumber=aggregate(SeedNumber~Trt+Species,Fitness,mean)

colnames(MeanSeedNumber)=c("Trt","Species","MeanSeedNumber")

Ipurp.Fit=Fitness%>%
  filter(Species=="Ip")

Ipurp.Alpha=alpha%>%
  filter(Species=="Ip")

FitnessPurp=merge(Ipurp.Fit,MeanSeedNumber,by=c("Trt","Species"))
FitnessPurp$RelativeFit=FitnessPurp$SeedNumber/FitnessPurp$MeanSeedNumber
FitnessPurp$Block=as.factor(FitnessPurp$Block)

FitnessPurp2=merge(FitnessPurp,LeafData)
str(FitnessPurp2)
## 'data.frame':    385 obs. of  24 variables:
##  $ Trt            : Factor w/ 2 levels "Alone","Inter": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Species        : Factor w/ 1 level "Ip": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Position       : Factor w/ 429 levels "102","106","107",..: 1 7 21 23 31 32 39 53 54 57 ...
##  $ Block          : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Order          : int  102 114 136 138 151 153 172 203 204 213 ...
##  $ ML             : Factor w/ 10 levels "PA4.11Ip","PA4.13Ip",..: 10 4 10 1 3 9 4 6 6 5 ...
##  $ UniqId         : Factor w/ 429 levels "102Ip","106Ip",..: 1 7 21 23 31 32 39 53 54 57 ...
##  $ GerminationDate: Factor w/ 5 levels "43258","43259",..: 1 1 1 1 1 1 3 3 1 1 ...
##  $ Comment1       : Factor w/ 2 levels "DG","LG": NA NA NA NA NA NA NA NA NA NA ...
##  $ Dead_plant     : Factor w/ 1 level "Y": NA NA NA NA NA NA NA NA NA NA ...
##  $ DeathCause     : logi  NA NA NA NA NA NA ...
##  $ RootsHarvested : Factor w/ 2 levels "N","Y": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SeedsCounted   : Factor w/ 1 level "Y": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Comp           : Factor w/ 6 levels "PA 4.12 Ihed",..: NA NA NA NA NA NA NA NA NA NA ...
##  $ Combos         : Factor w/ 60 levels "PA 4.1 Ip-PA 4.12 Ihed",..: NA NA NA NA NA NA NA NA NA NA ...
##  $ Population     : Factor w/ 1 level "PA4": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SeedNumber     : int  96 75 93 56 383 321 256 202 79 172 ...
##  $ MeanSeedNumber : num  224 224 224 224 224 ...
##  $ RelativeFit    : num  0.428 0.334 0.415 0.25 1.708 ...
##  $ Block.1        : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Leaf.Number    : int  6 5 6 7 9 10 11 7 7 8 ...
##  $ Comment        : logi  NA NA NA NA NA NA ...
##  $ X              : int  1 7 21 23 31 32 39 53 54 57 ...
##  $ Sample_ID      : chr  "102P" "114P" "136P" "138P" ...
FitnessPurp2$Leaf.Number=as.numeric(as.character(FitnessPurp2$Leaf.Number))

SN1<-lmer(SeedNumber~Trt+Block+Leaf.Number+Block:Trt+(1|ML),FitnessPurp2)
anova(SN1) # Treatment is significant effect on plant seed number; Significant Treatment by Block effect
## Type III Analysis of Variance Table with Satterthwaite's method
##              Sum Sq Mean Sq NumDF  DenDF  F value  Pr(>F)    
## Trt           83491   83491     1 370.05   3.9783 0.04682 *  
## Block        128423   42808     3 371.69   2.0398 0.10790    
## Leaf.Number 2425524 2425524     1 374.69 115.5752 < 2e-16 ***
## Trt:Block    164743   54914     3 371.54   2.6167 0.05082 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ggplot(FitnessPurp,aes(Trt,RelativeFit,fill=Block))+
  geom_boxplot()+
  scale_fill_brewer("Paired")+
  theme_classic()+
  ylab("Relative Fitness")+
  ggtitle("Relative Fitness by Treatment and Block")

# Remove size effects from fitness
StdFitness=FitnessPurp2[c("Trt","Species","Block","ML","RelativeFit","Leaf.Number")] # Subset fitness data for variables of interest

# Run one-way ANOVA to remove size effect--i.e., keep residuals
StdFitness$RelativeFitness=residuals(lm(RelativeFit~Leaf.Number,FitnessPurp2)) 

# Compare residuals and non-standard values of fitness
dev.off()
## null device 
##           1
plot(StdFitness$RelativeFit,StdFitness$RelativeFitness)

# Average fitness by block, maternal line and treatment--we use NON standardized fitness (ie size effects not removed)
FitAveraged=aggregate(RelativeFit~Block+Trt+ML,FitnessPurp,mean)
colnames(FitAveraged)<-c("Block","Trt","ML","RelativeFitness")
FitAveraged$TRT=FitAveraged$Trt
dim(FitAveraged)
## [1] 76  5
head(FitAveraged)
##   Block   Trt       ML RelativeFitness   TRT
## 1     1 Alone PA4.11Ip       0.4437172 Alone
## 2     2 Alone PA4.11Ip       1.0435158 Alone
## 3     3 Alone PA4.11Ip       1.0747321 Alone
## 4     4 Alone PA4.11Ip       1.4627059 Alone
## 5     1 Inter PA4.11Ip       0.6619616 Inter
## 6     2 Inter PA4.11Ip       0.6103389 Inter
# Average size
SizeAveraged=aggregate(Leaf.Number~Block+Trt+ML+Species,LeafData,mean)
colnames(SizeAveraged)<-c("Block","Trt","ML","Species","Size")
SizeAveraged$TRT=SizeAveraged$Trt
dim(SizeAveraged)
## [1] 76  6
head(SizeAveraged)
##   Block   Trt       ML Species      Size   TRT
## 1     1 Alone PA4.11Ip      Ip  9.000000 Alone
## 2     2 Alone PA4.11Ip      Ip 11.000000 Alone
## 3     3 Alone PA4.11Ip      Ip  8.000000 Alone
## 4     4 Alone PA4.11Ip      Ip  5.000000 Alone
## 5     1 Inter PA4.11Ip      Ip  7.545455 Inter
## 6     2 Inter PA4.11Ip      Ip  7.500000 Inter
SizePurp<-SizeAveraged%>%filter(Species=="Ip")
####  ####  ####  ####  ####  ####   ####
#  Examine selection on microbiome first
####  ####  ####  ####  ####  ####   ####
FitnessPurp$TRT=FitnessPurp$Trt
FitnessPurp$Combos=as.character(FitnessPurp$Combos)
FitnessPurp[which(FitnessPurp$Trt=="Alone"),]$Combos="none"
FitnessPurp$Combos=as.factor(FitnessPurp$Combos)

BrayFit=merge(physeq.pcoa.df,FitAveraged)

FitAlpha=merge(FitAveraged,alpha)
dim(FitAlpha)
## [1] 97 13
ggplot(FitAlpha,aes(TRT,RelativeFitness))+
  geom_boxplot()+
  scale_fill_brewer("Paired")+
  theme_classic()+
  ylab("Relative Fitness")+
  ggtitle("Relative Fitness by Treatment and Block")+
  facet_grid(~Block)

# Combine with root data
library(dplyr)

RootAveraged=aggregate(list(RootData[c("PC1","PC2","PC3","PC4")]),by=list(RootData$Trt,RootData$ML),FUN=mean) 

colnames(RootAveraged)=c("Trt","ML","PC1","PC2","PC3","PC4")
head(RootAveraged)
##     Trt         ML         PC1        PC2        PC3         PC4
## 1 Alone   PA4.11Ip -0.69794646 -1.3274069  0.7756816 -0.75520608
## 2 Inter   PA4.11Ip  0.43519578  0.6954043 -0.1859846  0.10761866
## 3 Inter PA4.12Ihed  0.07075942 -0.9146971 -0.2814713 -0.01631047
## 4 Alone   PA4.13Ip -2.28254650  1.4831488  0.9299528 -0.64140759
## 5 Inter   PA4.13Ip  0.11317327 -0.1860671  0.1006711  0.43992946
## 6 Alone   PA4.14Ip  0.70071833 -0.4492977  0.9728631 -0.41237743
RootFitAlpha=merge(FitAlpha,RootAveraged)
head(RootFitAlpha)
##         ML   Trt Block   TRT RelativeFitness Sample_ID Species
## 1 PA4.11Ip Alone     1 Alone       0.4437172      158P      Ip
## 2 PA4.11Ip Alone     1 Alone       0.4437172       84P      Ip
## 3 PA4.11Ip Alone     4 Alone       1.4627059      814P      Ip
## 4 PA4.11Ip Alone     3 Alone       1.0747321      674P      Ip
## 5 PA4.11Ip Inter     1 Inter       0.6619616      93AP      Ip
## 6 PA4.11Ip Inter     1 Inter       0.6619616       21P      Ip
##                    Combos rich  InvSimp       sim     shan       even
## 1                    none  443 31.85241 0.9686052 4.536983 0.01024150
## 2                    none  469 40.47708 0.9752947 4.739450 0.01010544
## 3                    none  471 49.18046 0.9796667 4.800749 0.01019267
## 4                    none  443 30.20342 0.9668912 4.479767 0.01011234
## 5 PA 4.11 Ip-PA 4.15 Ihed  432 34.99536 0.9714248 4.587454 0.01061911
## 6  PA 4.11 Ip-PA 4.3 Ihed  486 41.55300 0.9759344 4.745673 0.00976476
##          PC1        PC2        PC3        PC4
## 1 -0.6979465 -1.3274069  0.7756816 -0.7552061
## 2 -0.6979465 -1.3274069  0.7756816 -0.7552061
## 3 -0.6979465 -1.3274069  0.7756816 -0.7552061
## 4 -0.6979465 -1.3274069  0.7756816 -0.7552061
## 5  0.4351958  0.6954043 -0.1859846  0.1076187
## 6  0.4351958  0.6954043 -0.1859846  0.1076187
#RootFitLeafAlpha=merge(RootFitAlpha,LeafData[c("Sample_ID","Leaf.Number")],by="Sample_ID")

#RootFitLeafAlpha$Leaf.Number=as.numeric(as.character(RootFitLeafAlpha$Leaf.Number))


# CombinE root,fitness/bray estimates
RootFitBray=merge(BrayFit,RootAveraged)


# Plot boxplots of averaged root traits
PC2_Box=ggplot(RootAveraged,aes(x="",y=PC2))+
  geom_boxplot()+
  #geom_jitter()+
  xlab("Root Architecture")+
  theme_classic()+
  Tx+ 
  coord_flip()

# Plot boxplots of averaged root traits
PC1_Box=ggplot(RootAveraged,aes(x="",y=PC1))+
  geom_boxplot()+
  #geom_jitter()+
  xlab("Root Topology")+
  theme_classic()+
  Tx+ 
  coord_flip()

# Plot boxplots of averaged root traits
PC4_Box=ggplot(RootAveraged,aes(x="",y=PC4))+
  geom_boxplot()+
  #geom_jitter()+
  xlab("Root Morphology")+
  theme_classic()+
  Tx+ 
  coord_flip()

#ggarrange(P2.rich,P2.even,P4.Sim,P4.simIn,nrow=2,ncol=2)
AB=cowplot::plot_grid(P2.rich,P2.even,align = "hv", ncol = 2,labels =c("A","B"), label_size =22 ,hjust=-11,vjust=1,label_x = -0.16)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
ab=cowplot::plot_grid(P4.Sim,P4.simIn,align = "hv", ncol = 2,labels =c("A","B"), label_size =22 ,hjust=-11,vjust=1,label_x = -0.17)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
P4.simIn+
  xlab("Root morphology (PC4)")
## `geom_smooth()` using formula 'y ~ x'

# Common x title

x.grob <- textGrob("Root morphology (PC4)", 
                   gp=gpar(col="black", fontsize=25), rot=0)

gridExtra::grid.arrange(gridExtra::arrangeGrob(ab,bottom=x.grob,padding = unit(0.5,units = 'in'),nrow=1))

# Common x title
x.grob1 <- textGrob("Root architecture (PC2)", 
                   gp=gpar(col="black", fontsize=25), rot=0)

gridExtra::grid.arrange(gridExtra::arrangeGrob(AB,bottom=x.grob1,padding = unit(0.5,units = 'in'),nrow=1))

Selection on microbe variables

# Quadratic microbe term
FitAlpha$even2=(FitAlpha$even*FitAlpha$even)
FitAlpha$rich2=(FitAlpha$rich*FitAlpha$rich)
FitAlpha$InSim2=(FitAlpha$InvSimp*FitAlpha$InvSimp)
FitAlpha$sim2=(FitAlpha$sim*FitAlpha$sim)

Selection on richness

summary(lm(RelativeFitness~Block+rich+rich2,FitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + rich + rich2, data = FitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.79140 -0.16551  0.00835  0.14613  0.98238 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -4.225e-01  1.561e+01  -0.027   0.9787  
## Block2       2.227e-01  2.768e-01   0.804   0.4316  
## Block3       5.423e-01  3.247e-01   1.670   0.1123  
## Block4       6.396e-01  2.571e-01   2.488   0.0229 *
## rich         9.591e-04  6.938e-02   0.014   0.9891  
## rich2        2.624e-06  7.721e-05   0.034   0.9733  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4427 on 18 degrees of freedom
## Multiple R-squared:  0.3552, Adjusted R-squared:  0.1761 
## F-statistic: 1.983 on 5 and 18 DF,  p-value: 0.1301
summary(lm(RelativeFitness~Block+rich+rich2,FitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + rich + rich2, data = FitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40909 -0.10830 -0.01740  0.06575  0.68679 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -4.563e+00  3.295e+00  -1.385    0.171    
## Block2       6.645e-02  6.771e-02   0.981    0.330    
## Block3       7.799e-01  6.929e-02  11.256  < 2e-16 ***
## Block4       3.027e-01  7.006e-02   4.320 5.29e-05 ***
## rich         2.474e-02  1.516e-02   1.633    0.107    
## rich2       -2.891e-05  1.735e-05  -1.666    0.100    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2001 on 67 degrees of freedom
## Multiple R-squared:  0.717,  Adjusted R-squared:  0.6959 
## F-statistic: 33.95 on 5 and 67 DF,  p-value: < 2.2e-16
richness_sel=lm(RelativeFitness~TRT*Block+rich,FitAlpha)
summary(richness_sel) # No evidence of indirect selection
## 
## Call:
## lm(formula = RelativeFitness ~ TRT * Block + rich, data = FitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71196 -0.12913 -0.03669  0.10339  0.98681 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.4565102  0.4562438   1.001 0.319771    
## TRTInter         0.1178495  0.1305712   0.903 0.369219    
## Block2           0.1530488  0.1585365   0.965 0.336998    
## Block3           0.6301298  0.1666124   3.782 0.000283 ***
## Block4           0.5881335  0.1521200   3.866 0.000211 ***
## rich             0.0002558  0.0009621   0.266 0.790984    
## TRTInter:Block2 -0.0670337  0.1824968  -0.367 0.714267    
## TRTInter:Block3  0.1244367  0.1874137   0.664 0.508447    
## TRTInter:Block4 -0.2594529  0.1780784  -1.457 0.148687    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2718 on 88 degrees of freedom
## Multiple R-squared:  0.5685, Adjusted R-squared:  0.5292 
## F-statistic: 14.49 on 8 and 88 DF,  p-value: 2.733e-13
anova(richness_sel)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## TRT        1 0.1156 0.11565  1.5656    0.2142    
## Block      3 8.0999 2.69998 36.5513 1.955e-15 ***
## rich       1 0.0006 0.00059  0.0079    0.9292    
## TRT:Block  3 0.3471 0.11570  1.5664    0.2032    
## Residuals 88 6.5004 0.07387                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ggplot(FitAlpha)+
  geom_point(aes(RelativeFitness,rich),alpha=0.5,size=5)+
  geom_smooth(method="lm",aes(RelativeFitness,rich),fullrange=TRUE)+
  theme_classic()+
  ylab("Relative fitness")+
  xlab("Richness")+
  Tx2
## `geom_smooth()` using formula 'y ~ x'

Selection on Inverse Simpson

summary(lm(RelativeFitness~Block+InvSimp+InSim2,FitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + InvSimp + InSim2, data = FitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72828 -0.16024 -0.05544  0.15054  0.99454 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  0.8744784  2.3659317   0.370   0.7160  
## Block2       0.1476774  0.2696585   0.548   0.5907  
## Block3       0.6139853  0.2879193   2.132   0.0470 *
## Block4       0.5781498  0.2650997   2.181   0.0427 *
## InvSimp     -0.0194253  0.1231302  -0.158   0.8764  
## InSim2       0.0002973  0.0016102   0.185   0.8556  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4522 on 18 degrees of freedom
## Multiple R-squared:  0.3274, Adjusted R-squared:  0.1406 
## F-statistic: 1.753 on 5 and 18 DF,  p-value: 0.1737
summary(lm(RelativeFitness~Block+InvSimp+InSim2,FitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + InvSimp + InSim2, data = FitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39125 -0.10854 -0.02030  0.06625  0.71852 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.830e-01  2.687e-01   3.286  0.00162 ** 
## Block2       9.491e-02  6.865e-02   1.382  0.17142    
## Block3       7.748e-01  7.062e-02  10.970  < 2e-16 ***
## Block4       3.221e-01  7.008e-02   4.596 1.96e-05 ***
## InvSimp     -8.561e-03  1.356e-02  -0.632  0.52985    
## InSim2       8.071e-05  1.665e-04   0.485  0.62936    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2033 on 67 degrees of freedom
## Multiple R-squared:  0.7078, Adjusted R-squared:  0.686 
## F-statistic: 32.46 on 5 and 67 DF,  p-value: < 2.2e-16
Invn_sel=lm(RelativeFitness~TRT*Block+InvSimp+Block,FitAlpha)
summary(Invn_sel) # No evidence of indirect selection
## 
## Call:
## lm(formula = RelativeFitness ~ TRT * Block + InvSimp + Block, 
##     data = FitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.70581 -0.14022 -0.02634  0.10538  0.98955 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.627240   0.164324   3.817 0.000251 ***
## TRTInter         0.108641   0.129286   0.840 0.403010    
## Block2           0.142704   0.157121   0.908 0.366229    
## Block3           0.640412   0.164643   3.890 0.000195 ***
## Block4           0.580133   0.151326   3.834 0.000237 ***
## InvSimp         -0.001360   0.003106  -0.438 0.662675    
## TRTInter:Block2 -0.053652   0.182000  -0.295 0.768848    
## TRTInter:Block3  0.132110   0.188137   0.702 0.484407    
## TRTInter:Block4 -0.256351   0.177514  -1.444 0.152258    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2716 on 88 degrees of freedom
## Multiple R-squared:  0.5691, Adjusted R-squared:  0.5299 
## F-statistic: 14.53 on 8 and 88 DF,  p-value: 2.58e-13
ggplot(FitAlpha)+
  geom_point(aes(RelativeFitness,InvSimp),alpha=0.5,size=5)+
  geom_smooth(method="lm",aes(RelativeFitness,InvSimp),fullrange=TRUE)+
  theme_classic()+
  ylab("Relative fitness")+
  xlab("Inverse Simpson")+
  Tx2
## `geom_smooth()` using formula 'y ~ x'

Selection on Simpson

summary(lm(RelativeFitness~Block+sim+sim2,FitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + sim + sim2, data = FitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73020 -0.15925 -0.01442  0.14021  0.98152 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  113.7563  2548.9022   0.045   0.9649  
## Block2         0.1563     0.2691   0.581   0.5685  
## Block3         0.6308     0.2812   2.243   0.0377 *
## Block4         0.5915     0.2627   2.252   0.0371 *
## sim         -236.8309  5252.7315  -0.045   0.9645  
## sim2         123.8459  2706.1541   0.046   0.9640  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4527 on 18 degrees of freedom
## Multiple R-squared:  0.3257, Adjusted R-squared:  0.1385 
## F-statistic: 1.739 on 5 and 18 DF,  p-value: 0.1767
summary(lm(RelativeFitness~Block+sim+sim2,FitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + sim + sim2, data = FitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39853 -0.12744 -0.02723  0.06812  0.69878 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -161.47060  174.42097  -0.926    0.358    
## Block2         0.08882    0.06838   1.299    0.198    
## Block3         0.78244    0.06950  11.259  < 2e-16 ***
## Block4         0.31980    0.06979   4.582 2.06e-05 ***
## sim          338.30099  361.47826   0.936    0.353    
## sim2        -176.40402  187.27506  -0.942    0.350    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2025 on 67 degrees of freedom
## Multiple R-squared:   0.71,  Adjusted R-squared:  0.6883 
## F-statistic: 32.81 on 5 and 67 DF,  p-value: < 2.2e-16
sim_sel=lm(RelativeFitness~TRT*Block+sim,FitAlpha)
summary(sim_sel) # NS
## 
## Call:
## lm(formula = RelativeFitness ~ TRT * Block + sim, data = FitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.70371 -0.13867 -0.02266  0.09800  0.98995 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      2.03554    3.58756   0.567 0.571895    
## TRTInter         0.10621    0.12993   0.817 0.415883    
## Block2           0.14248    0.15723   0.906 0.367316    
## Block3           0.63853    0.16453   3.881 0.000201 ***
## Block4           0.57937    0.15150   3.824 0.000245 ***
## sim             -1.50026    3.68123  -0.408 0.684600    
## TRTInter:Block2 -0.05202    0.18262  -0.285 0.776440    
## TRTInter:Block3  0.13144    0.18813   0.699 0.486619    
## TRTInter:Block4 -0.25457    0.17758  -1.434 0.155238    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2716 on 88 degrees of freedom
## Multiple R-squared:  0.5689, Adjusted R-squared:  0.5298 
## F-statistic: 14.52 on 8 and 88 DF,  p-value: 2.612e-13
ggplot(FitAlpha)+
  geom_point(aes(RelativeFitness,sim),alpha=0.5,size=5)+
  geom_smooth(method="lm",aes(RelativeFitness,sim),fullrange=TRUE)+
  theme_classic()+
  ylab("Relative fitness")+
  xlab("Simpson")+
  Tx2
## `geom_smooth()` using formula 'y ~ x'

Selection on Evenness

summary(lm(RelativeFitness~Block+even+even2 ,FitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + even + even2, data = FitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.82007 -0.15847  0.00148  0.13980  0.99277 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -3.344e+00  3.941e+01  -0.085   0.9333  
## Block2       2.484e-01  2.763e-01   0.899   0.3805  
## Block3       5.492e-01  3.258e-01   1.685   0.1092  
## Block4       6.486e-01  2.550e-01   2.544   0.0204 *
## even         1.011e+03  7.594e+03   0.133   0.8955  
## even2       -6.154e+04  3.661e+05  -0.168   0.8684  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4398 on 18 degrees of freedom
## Multiple R-squared:  0.3637, Adjusted R-squared:  0.187 
## F-statistic: 2.058 on 5 and 18 DF,  p-value: 0.1186
summary(lm(RelativeFitness~Block+even+even2,FitAlpha%>%filter(TRT!="Alone"))) # Significant quadratic term for evenness on fitnes (super low slope tho)
## 
## Call:
## lm(formula = RelativeFitness ~ Block + even + even2, data = FitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43781 -0.11504 -0.03577  0.08246  0.68928 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.991e+01  8.357e+00  -2.382   0.0200 *  
## Block2       9.363e-02  6.588e-02   1.421   0.1598    
## Block3       7.744e-01  6.681e-02  11.590  < 2e-16 ***
## Block4       3.112e-01  6.761e-02   4.602 1.92e-05 ***
## even         3.920e+03  1.591e+03   2.464   0.0163 *  
## even2       -1.862e+05  7.566e+04  -2.461   0.0164 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.196 on 67 degrees of freedom
## Multiple R-squared:  0.7284, Adjusted R-squared:  0.7081 
## F-statistic: 35.93 on 5 and 67 DF,  p-value: < 2.2e-16
even_sel=lm(RelativeFitness~Trt*Block+TRT*even2+even,FitAlpha) # if we include block by treatment interaction there is marginal significance for a treatment by evenness squared effect
even_sel2=lm(RelativeFitness~Block+TRT*even2+even,FitAlpha) # if we include block by treatment interaction there is marginal significance for a treatment by evenness squared effect

anova(even_sel,even_sel2) # Based on RSS--second model/simpler one is a bit better
## Analysis of Variance Table
## 
## Model 1: RelativeFitness ~ Trt * Block + TRT * even2 + even
## Model 2: RelativeFitness ~ Block + TRT * even2 + even
##   Res.Df   RSS Df Sum of Sq      F  Pr(>F)  
## 1     86 6.079                              
## 2     89 6.596 -3  -0.51695 2.4378 0.07003 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(even_sel) # NS
## Analysis of Variance Table
## 
## Response: RelativeFitness
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## Trt        1 0.1156 0.11565  1.6361   0.20430    
## Block      3 8.0999 2.69998 38.1967 8.693e-16 ***
## even2      1 0.0103 0.01034  0.1463   0.70302    
## even       1 0.1970 0.19695  2.7863   0.09871 .  
## Trt:Block  3 0.3230 0.10767  1.5232   0.21426    
## TRT:even2  1 0.2388 0.23877  3.3779   0.06953 .  
## Residuals 86 6.0790 0.07069                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ggplot(FitAlpha)+
  geom_point(aes(RelativeFitness,even),alpha=0.5,size=5)+
  stat_smooth(method="lm",formula = y ~poly(x,2),aes(RelativeFitness,even))+
  theme_classic()+
  ylab("Relative fitness")+
  xlab("Evenness")+
  Tx2

# Remove block effects from fitness
RootFitAlpha$FitResidBlk<-resid(lm(RelativeFitness~Block,RootFitAlpha))

RootFitAlpha$Comp<-sub(".*\\-","",RootFitAlpha$Combos)
# PC1 and richness

richPC1=lm(RelativeFitness~PC1*rich*Trt*Block-PC1:rich:Trt:Block,RootFitAlpha)
#summary(richPC1)

anova(richPC1)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC1             1 0.1572 0.15720  2.6474 0.1083472    
## rich            1 0.7744 0.77437 13.0411 0.0005784 ***
## Trt             1 0.1057 0.10568  1.7797 0.1866326    
## Block           3 7.2159 2.40529 40.5074 3.933e-15 ***
## PC1:rich        1 0.0000 0.00002  0.0004 0.9848097    
## PC1:Trt         1 0.0086 0.00860  0.1448 0.7047266    
## rich:Trt        1 0.0105 0.01046  0.1762 0.6759774    
## PC1:Block       3 0.5911 0.19704  3.3183 0.0248966 *  
## rich:Block      3 0.2154 0.07180  1.2091 0.3131001    
## Trt:Block       3 0.1673 0.05578  0.9393 0.4265873    
## PC1:rich:Trt    1 0.0721 0.07211  1.2145 0.2743372    
## PC1:rich:Block  3 0.6228 0.20759  3.4960 0.0201213 *  
## PC1:Trt:Block   3 0.9197 0.30657  5.1629 0.0028326 ** 
## rich:Trt:Block  3 0.1653 0.05510  0.9279 0.4321120    
## Residuals      68 4.0378 0.05938                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Within treatment w block removed

summary(lm(FitResidBlk~rich+PC1,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = FitResidBlk ~ rich + PC1, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.78070 -0.20666  0.02256  0.14172  0.88602 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.2122161  1.2912061  -0.164    0.871
## rich         0.0004741  0.0028073   0.169    0.868
## PC1          0.0321677  0.0728484   0.442    0.663
## 
## Residual standard error: 0.4319 on 21 degrees of freedom
## Multiple R-squared:  0.01116,    Adjusted R-squared:  -0.08302 
## F-statistic: 0.1185 on 2 and 21 DF,  p-value: 0.8889
summary(lm(FitResidBlk~rich+PC1,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = FitResidBlk ~ rich + PC1, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43010 -0.09771 -0.03501  0.08772  0.75569 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.0992588  0.3370733   0.294    0.769
## rich        -0.0001961  0.0007567  -0.259    0.796
## PC1          0.0145365  0.0324388   0.448    0.655
## 
## Residual standard error: 0.2027 on 70 degrees of freedom
## Multiple R-squared:  0.003209,   Adjusted R-squared:  -0.02527 
## F-statistic: 0.1127 on 2 and 70 DF,  p-value: 0.8936
# PC2 and richness
summary(lm(RelativeFitness~PC2*rich*Block,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC2 * rich * Block, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.75212 -0.06477  0.02312  0.11124  0.75503 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)
## (Intercept)      8.491e-01  1.170e+01   0.073    0.944
## PC2              4.371e-01  9.655e+00   0.045    0.965
## rich            -5.203e-04  2.522e-02  -0.021    0.984
## Block2           2.727e-01  1.236e+01   0.022    0.983
## Block3           1.391e+01  1.515e+01   0.919    0.385
## Block4          -1.308e+00  1.217e+01  -0.107    0.917
## PC2:rich        -8.395e-04  2.093e-02  -0.040    0.969
## PC2:Block2       1.332e+00  1.051e+01   0.127    0.902
## PC2:Block3       3.069e+01  1.921e+01   1.598    0.149
## PC2:Block4       1.955e-02  1.056e+01   0.002    0.999
## rich:Block2     -8.649e-05  2.671e-02  -0.003    0.997
## rich:Block3     -2.777e-02  3.209e-02  -0.865    0.412
## rich:Block4      3.858e-03  2.639e-02   0.146    0.887
## PC2:rich:Block2 -3.053e-03  2.296e-02  -0.133    0.898
## PC2:rich:Block3 -6.754e-02  4.164e-02  -1.622    0.143
## PC2:rich:Block4 -6.021e-04  2.326e-02  -0.026    0.980
## 
## Residual standard error: 0.4923 on 8 degrees of freedom
## Multiple R-squared:  0.6457, Adjusted R-squared:  -0.01864 
## F-statistic: 0.9719 on 15 and 8 DF,  p-value: 0.5432
summary(lm(RelativeFitness~PC2*rich*Block,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC2 * rich * Block, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.45821 -0.07770 -0.02237  0.08282  0.56703 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      1.152e+00  5.414e-01   2.128   0.0377 *
## PC2             -2.461e-02  8.424e-01  -0.029   0.9768  
## rich            -1.050e-03  1.228e-03  -0.855   0.3959  
## Block2          -4.257e-01  9.710e-01  -0.438   0.6627  
## Block3           1.298e+00  9.152e-01   1.418   0.1616  
## Block4          -1.991e+00  1.226e+00  -1.624   0.1100  
## PC2:rich        -2.843e-05  1.928e-03  -0.015   0.9883  
## PC2:Block2       2.477e-01  1.588e+00   0.156   0.8766  
## PC2:Block3       3.295e+00  2.090e+00   1.577   0.1203  
## PC2:Block4       8.472e-01  2.494e+00   0.340   0.7353  
## rich:Block2      1.163e-03  2.194e-03   0.530   0.5980  
## rich:Block3     -1.101e-03  2.007e-03  -0.548   0.5856  
## rich:Block4      5.300e-03  2.771e-03   1.912   0.0609 .
## PC2:rich:Block2 -8.457e-04  3.570e-03  -0.237   0.8136  
## PC2:rich:Block3 -6.687e-03  4.469e-03  -1.496   0.1401  
## PC2:rich:Block4 -1.126e-03  5.618e-03  -0.200   0.8419  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1882 on 57 degrees of freedom
## Multiple R-squared:  0.7871, Adjusted R-squared:  0.731 
## F-statistic: 14.04 on 15 and 57 DF,  p-value: 5.429e-14
richPC2=lm(RelativeFitness~PC2*rich*Trt*Block-PC2:rich:Trt:Block,RootFitAlpha)

anova(richPC2)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC2             1 0.0335 0.03349  0.5013 0.4813678    
## rich            1 0.8044 0.80440 12.0392 0.0009089 ***
## Trt             1 0.2590 0.25904  3.8770 0.0530293 .  
## Block           3 7.1307 2.37690 35.5745 6.098e-14 ***
## PC2:rich        1 0.0025 0.00249  0.0372 0.8476339    
## PC2:Trt         1 0.0432 0.04323  0.6469 0.4240096    
## rich:Trt        1 0.0136 0.01364  0.2042 0.6528072    
## PC2:Block       3 0.0946 0.03153  0.4720 0.7028213    
## rich:Block      3 0.2088 0.06959  1.0415 0.3798857    
## Trt:Block       3 0.3429 0.11429  1.7106 0.1730218    
## PC2:rich:Trt    1 0.0095 0.00949  0.1421 0.7073849    
## PC2:rich:Block  3 0.3372 0.11239  1.6822 0.1790121    
## PC2:Trt:Block   3 1.2357 0.41189  6.1646 0.0009058 ***
## rich:Trt:Block  3 0.0047 0.00157  0.0235 0.9950628    
## Residuals      68 4.5434 0.06681                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Phenotypic selection on root architecture according to block and treatment--significant interaction between PC2, richness, treatment and block




# PC3 and richness
summary(lm(RelativeFitness~Block*PC3*rich,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block * PC3 * rich, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43811 -0.10466  0.00042  0.07339  0.88436 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)     -10.52245   34.19258  -0.308    0.766
## Block2           10.98549   34.38835   0.319    0.758
## Block3           24.40983   41.53757   0.588    0.573
## Block4           20.09306   35.66792   0.563    0.589
## PC3              12.68878   41.58761   0.305    0.768
## rich              0.02341    0.07206   0.325    0.754
## Block2:PC3      -14.25921   41.80697  -0.341    0.742
## Block3:PC3      -33.04273   51.00990  -0.648    0.535
## Block4:PC3      -20.59474   43.06326  -0.478    0.645
## Block2:rich      -0.02266    0.07254  -0.312    0.763
## Block3:rich      -0.04798    0.08519  -0.563    0.589
## Block4:rich      -0.03986    0.07523  -0.530    0.611
## PC3:rich         -0.02684    0.08812  -0.305    0.768
## Block2:PC3:rich   0.03013    0.08866   0.340    0.743
## Block3:PC3:rich   0.06729    0.10518   0.640    0.540
## Block4:PC3:rich   0.04133    0.09128   0.453    0.663
## 
## Residual standard error: 0.4835 on 8 degrees of freedom
## Multiple R-squared:  0.6583, Adjusted R-squared:  0.0175 
## F-statistic: 1.027 on 15 and 8 DF,  p-value: 0.5084
summary(lm(RelativeFitness~Block*PC3*rich,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block * PC3 * rich, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39876 -0.08191 -0.02446  0.06407  0.48998 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      1.0452625  0.6052994   1.727   0.0896 .
## Block2          -0.8173359  0.9280059  -0.881   0.3822  
## Block3           2.3109108  1.1116370   2.079   0.0421 *
## Block4          -0.3914877  1.0899094  -0.359   0.7208  
## PC3              0.0590131  1.7451974   0.034   0.9731  
## rich            -0.0008076  0.0013886  -0.582   0.5631  
## Block2:PC3      -0.0830240  2.2172878  -0.037   0.9703  
## Block3:PC3      -7.9595873  4.1043488  -1.939   0.0574 .
## Block4:PC3      -1.0978146  3.0536554  -0.360   0.7205  
## Block2:rich      0.0019886  0.0021187   0.939   0.3519  
## Block3:rich     -0.0031651  0.0024337  -1.301   0.1987  
## Block4:rich      0.0016710  0.0025123   0.665   0.5087  
## PC3:rich        -0.0003039  0.0042277  -0.072   0.9429  
## Block2:PC3:rich  0.0008147  0.0052460   0.155   0.8771  
## Block3:PC3:rich  0.0161945  0.0088796   1.824   0.0734 .
## Block4:PC3:rich  0.0023786  0.0071130   0.334   0.7393  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1938 on 57 degrees of freedom
## Multiple R-squared:  0.7742, Adjusted R-squared:  0.7147 
## F-statistic: 13.03 on 15 and 57 DF,  p-value: 2.615e-13
richPC3=lm(RelativeFitness~PC3*rich*Trt*Block-PC3:rich:Trt:Block,RootFitAlpha)

anova(richPC3) # Significant richness effect
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC3             1 0.1472 0.14717  2.4483 0.1222966    
## rich            1 0.9017 0.90166 14.9998 0.0002441 ***
## Trt             1 0.0665 0.06651  1.1064 0.2965797    
## Block           3 7.3184 2.43947 40.5825 3.779e-15 ***
## PC3:rich        1 0.0156 0.01558  0.2591 0.6123829    
## PC3:Trt         1 0.0898 0.08983  1.4944 0.2257586    
## rich:Trt        1 0.0097 0.00970  0.1614 0.6891054    
## PC3:Block       3 0.3439 0.11463  1.9070 0.1366853    
## rich:Block      3 0.1886 0.06285  1.0456 0.3781295    
## Trt:Block       3 0.5922 0.19741  3.2840 0.0259439 *  
## PC3:rich:Trt    1 0.2373 0.23729  3.9475 0.0509707 .  
## PC3:rich:Block  3 0.5972 0.19906  3.3115 0.0251024 *  
## PC3:Trt:Block   3 0.3319 0.11065  1.8407 0.1480213    
## rich:Trt:Block  3 0.1362 0.04539  0.7550 0.5232594    
## Residuals      68 4.0876 0.06011                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(richPC3)
## 
## Call:
## lm(formula = RelativeFitness ~ PC3 * rich * Trt * Block - PC3:rich:Trt:Block, 
##     data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54717 -0.09467  0.00121  0.06952  0.86706 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)  
## (Intercept)           0.7934288  6.0893893   0.130   0.8967  
## PC3                  -1.7912322  3.6311645  -0.493   0.6234  
## rich                 -0.0004125  0.0129428  -0.032   0.9747  
## TrtInter              0.2394549  6.0901832   0.039   0.9688  
## Block2               -0.0678830  6.0838280  -0.011   0.9911  
## Block3                5.8685034  7.2257215   0.812   0.4195  
## Block4                6.4827149  6.5202879   0.994   0.3236  
## PC3:rich              0.0038413  0.0076766   0.500   0.6184  
## PC3:TrtInter          2.0310950  2.6859550   0.756   0.4521  
## rich:TrtInter        -0.0003614  0.0129342  -0.028   0.9778  
## PC3:Block2           -0.2626247  3.0679137  -0.086   0.9320  
## PC3:Block3           -9.3501717  5.4372185  -1.720   0.0900 .
## PC3:Block4           -3.4154144  3.9150703  -0.872   0.3861  
## rich:Block2           0.0005663  0.0129780   0.044   0.9653  
## rich:Block3          -0.0102484  0.0148849  -0.689   0.4935  
## rich:Block4          -0.0111626  0.0138772  -0.804   0.4240  
## TrtInter:Block2      -0.7474835  6.1371196  -0.122   0.9034  
## TrtInter:Block3      -3.3957436  6.9593233  -0.488   0.6272  
## TrtInter:Block4      -6.7298917  6.4612809  -1.042   0.3013  
## PC3:rich:TrtInter    -0.0045850  0.0056217  -0.816   0.4176  
## PC3:rich:Block2       0.0005564  0.0064865   0.086   0.9319  
## PC3:rich:Block3       0.0186962  0.0107710   1.736   0.0871 .
## PC3:rich:Block4       0.0048847  0.0082915   0.589   0.5577  
## PC3:TrtInter:Block2   0.3051472  0.5331783   0.572   0.5690  
## PC3:TrtInter:Block3   0.2294980  0.6945541   0.330   0.7421  
## PC3:TrtInter:Block4   1.2326639  0.5739178   2.148   0.0353 *
## rich:TrtInter:Block2  0.0014111  0.0131000   0.108   0.9145  
## rich:TrtInter:Block3  0.0067307  0.0143649   0.469   0.6409  
## rich:TrtInter:Block4  0.0124899  0.0137449   0.909   0.3667  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2452 on 68 degrees of freedom
## Multiple R-squared:  0.7286, Adjusted R-squared:  0.6169 
## F-statistic: 6.521 on 28 and 68 DF,  p-value: 1.461e-10
# With block removed

Model1a<-(lm(RelativeFitness~rich+PC3,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~rich+PC3,RootFitAlpha%>%filter(TRT!="Alone"))) # Richness is significant when Block is not in the model, and marginal with the interaction

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ rich + PC3, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5014 -0.3234 -0.2056  0.2228  1.2122 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.513143   1.508149  -0.340    0.737
## rich         0.003321   0.003240   1.025    0.317
## PC3         -0.127941   0.200651  -0.638    0.531
## 
## Residual standard error: 0.49 on 21 degrees of freedom
## Multiple R-squared:  0.07855,    Adjusted R-squared:  -0.009212 
## F-statistic: 0.895 on 2 and 21 DF,  p-value: 0.4236
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ rich + PC3, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56635 -0.30499 -0.00652  0.22647  1.10383 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.276641   0.580838  -0.476   0.6354  
## rich         0.002862   0.001305   2.192   0.0317 *
## PC3         -0.032345   0.116139  -0.279   0.7814  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3559 on 70 degrees of freedom
## Multiple R-squared:  0.06429,    Adjusted R-squared:  0.03756 
## F-statistic: 2.405 on 2 and 70 DF,  p-value: 0.0977
# Significant Block effects
# PC3:rich:Block Significant
# TRT:Block significant
# PC3:rich:TRT significant

# PC4 and richness
richPC4=lm(RelativeFitness~PC4*rich*Trt*Block-PC4:rich:Trt:Block,RootFitAlpha)

anova(richPC4)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC4             1 0.3109 0.31087  4.6331  0.034913 *  
## rich            1 0.6603 0.66034  9.8413  0.002522 ** 
## Trt             1 0.1668 0.16681  2.4860  0.119507    
## Block           3 7.0800 2.36001 35.1722 7.702e-14 ***
## PC4:rich        1 0.0934 0.09341  1.3921  0.242158    
## PC4:Trt         1 0.0019 0.00195  0.0291  0.865166    
## rich:Trt        1 0.0491 0.04909  0.7316  0.395383    
## PC4:Block       3 0.6386 0.21288  3.1727  0.029658 *  
## rich:Block      3 0.0859 0.02865  0.4269  0.734337    
## Trt:Block       3 0.4349 0.14498  2.1607  0.100663    
## PC4:rich:Trt    1 0.0011 0.00108  0.0160  0.899568    
## PC4:rich:Block  3 0.1313 0.04378  0.6525  0.584157    
## PC4:Trt:Block   3 0.1802 0.06006  0.8951  0.448329    
## rich:Trt:Block  3 0.6664 0.22212  3.3103  0.025136 *  
## Residuals      68 4.5627 0.06710                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant PC4:Block
# PC4:Block
# Trt:Block
# rich:TRT:Block
# PC4:rich:TRT:Block
# Block

# PC3 and simpson
simPC1<-(lm(RelativeFitness~PC1*sim*TRT*Block-PC1:sim:TRT:Block,RootFitAlpha))

anova(simPC1)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##               Df Sum Sq Mean Sq F value    Pr(>F)    
## PC1            1 0.1572 0.15720  2.6464   0.10841    
## sim            1 0.1068 0.10681  1.7981   0.18440    
## TRT            1 0.0331 0.03309  0.5571   0.45800    
## Block          3 7.9690 2.65634 44.7194 4.455e-16 ***
## PC1:sim        1 0.0568 0.05682  0.9565   0.33154    
## PC1:TRT        1 0.0086 0.00855  0.1440   0.70551    
## sim:TRT        1 0.0259 0.02592  0.4364   0.51109    
## PC1:Block      3 0.6054 0.20180  3.3973   0.02265 *  
## sim:Block      3 0.0056 0.00188  0.0317   0.99234    
## TRT:Block      3 0.1548 0.05159  0.8686   0.46178    
## PC1:sim:TRT    1 0.0233 0.02327  0.3918   0.53344    
## PC1:sim:Block  3 0.1336 0.04454  0.7498   0.52623    
## PC1:TRT:Block  3 1.4721 0.49069  8.2608 9.202e-05 ***
## sim:TRT:Block  3 0.2723 0.09075  1.5278   0.21518    
## Residuals     68 4.0392 0.05940                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# PC1:TRT:Block Significant
# PC1:Block
# Block


# PC2 and simpson
simPC2<-(lm(RelativeFitness~PC2*sim*TRT*Block-PC2:sim:TRT:Block,RootFitAlpha))

anova(simPC2)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##               Df Sum Sq Mean Sq F value    Pr(>F)    
## PC2            1 0.0335 0.03349  0.5049 0.4798031    
## sim            1 0.1283 0.12825  1.9333 0.1689337    
## TRT            1 0.1738 0.17376  2.6192 0.1102051    
## Block          3 7.8984 2.63279 39.6873 6.111e-15 ***
## PC2:sim        1 0.0018 0.00185  0.0279 0.8679312    
## PC2:TRT        1 0.0340 0.03399  0.5124 0.4765544    
## sim:TRT        1 0.0002 0.00023  0.0035 0.9529224    
## PC2:Block      3 0.1113 0.03710  0.5593 0.6437035    
## sim:Block      3 0.0173 0.00577  0.0869 0.9669815    
## TRT:Block      3 0.2675 0.08918  1.3443 0.2673307    
## PC2:sim:TRT    1 0.0002 0.00016  0.0024 0.9609559    
## PC2:sim:Block  3 0.3233 0.10775  1.6243 0.1918210    
## PC2:TRT:Block  3 1.3067 0.43557  6.5659 0.0005786 ***
## sim:TRT:Block  3 0.2565 0.08549  1.2887 0.2853277    
## Residuals     68 4.5110 0.06634                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(simPC2)
## 
## Call:
## lm(formula = RelativeFitness ~ PC2 * sim * TRT * Block - PC2:sim:TRT:Block, 
##     data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57386 -0.08097 -0.01539  0.07065  0.95971 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)   
## (Intercept)          10.31355   54.25290   0.190  0.84980   
## PC2                  16.63819   21.60503   0.770  0.44390   
## sim                  -9.90900   55.60967  -0.178  0.85910   
## TRTInter             -1.46047   55.59757  -0.026  0.97912   
## Block2                5.90379   57.53744   0.103  0.91858   
## Block3              -42.35539   57.49005  -0.737  0.46381   
## Block4               21.37072   54.35342   0.393  0.69542   
## PC2:sim             -17.00262   22.12012  -0.769  0.44476   
## PC2:TRTInter        -21.65901   18.94739  -1.143  0.25700   
## sim:TRTInter          1.50405   56.99176   0.026  0.97902   
## PC2:Block2           10.98674   21.29535   0.516  0.60758   
## PC2:Block3           18.73036   20.97436   0.893  0.37500   
## PC2:Block4            3.89781   17.58602   0.222  0.82526   
## sim:Block2           -5.83751   59.01585  -0.099  0.92150   
## sim:Block3           43.88540   58.93391   0.745  0.45905   
## sim:Block4          -21.77280   55.71615  -0.391  0.69718   
## TRTInter:Block2      -9.57544   59.10553  -0.162  0.87178   
## TRTInter:Block3      35.16565   59.38576   0.592  0.55571   
## TRTInter:Block4     -35.42532   56.57604  -0.626  0.53331   
## PC2:sim:TRTInter     22.11197   19.39931   1.140  0.25835   
## PC2:sim:Block2      -11.34609   21.83431  -0.520  0.60500   
## PC2:sim:Block3      -19.89275   21.55102  -0.923  0.35924   
## PC2:sim:Block4       -4.44916   18.04588  -0.247  0.80600   
## PC2:TRTInter:Block2  -0.05497    0.22580  -0.243  0.80837   
## PC2:TRTInter:Block3   0.83206    0.29892   2.784  0.00696 **
## PC2:TRTInter:Block4   0.73181    0.29575   2.474  0.01585 * 
## sim:TRTInter:Block2   9.72127   60.63200   0.160  0.87309   
## sim:TRTInter:Block3 -35.70578   60.87591  -0.587  0.55946   
## sim:TRTInter:Block4  36.60244   58.00381   0.631  0.53013   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2576 on 68 degrees of freedom
## Multiple R-squared:  0.7005, Adjusted R-squared:  0.5772 
## F-statistic: 5.681 on 28 and 68 DF,  p-value: 2.559e-09
Model1a<-(lm(RelativeFitness~sim*PC2*Block,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~sim*PC2*Block,RootFitAlpha%>%filter(TRT!="Alone"))) 

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ sim * PC2 * Block, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.58339 -0.06284  0.00532  0.05732  0.94429 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## (Intercept)     -102.04     345.26  -0.296    0.775
## sim              105.08     353.39   0.297    0.774
## PC2              -69.47     257.04  -0.270    0.794
## Block2           116.24     348.30   0.334    0.747
## Block3           422.38     399.60   1.057    0.321
## Block4           132.07     346.67   0.381    0.713
## sim:PC2           71.16     263.17   0.270    0.794
## sim:Block2      -118.77     356.52  -0.333    0.748
## sim:Block3      -432.26     409.15  -1.056    0.322
## sim:Block4      -135.03     354.86  -0.381    0.713
## PC2:Block2        93.93     259.54   0.362    0.727
## PC2:Block3       587.87     371.74   1.581    0.152
## PC2:Block4        86.66     259.23   0.334    0.747
## sim:PC2:Block2   -96.25     265.75  -0.362    0.727
## sim:PC2:Block3  -605.03     381.58  -1.586    0.151
## sim:PC2:Block4   -89.14     265.47  -0.336    0.746
## 
## Residual standard error: 0.4552 on 8 degrees of freedom
## Multiple R-squared:  0.6971, Adjusted R-squared:  0.1293 
## F-statistic: 1.228 on 15 and 8 DF,  p-value: 0.3987
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ sim * PC2 * Block, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.45095 -0.06926 -0.00438  0.06992  0.61829 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)       8.703      5.528   1.574   0.1209  
## sim              -8.251      5.692  -1.450   0.1526  
## PC2              -4.568      7.918  -0.577   0.5663  
## Block2           -3.100      9.657  -0.321   0.7494  
## Block3           -6.913      8.180  -0.845   0.4016  
## Block4          -14.171      7.580  -1.869   0.0667 .
## sim:PC2           4.642      8.163   0.569   0.5718  
## sim:Block2        3.298      9.930   0.332   0.7410  
## sim:Block3        7.904      8.404   0.941   0.3509  
## sim:Block4       14.948      7.814   1.913   0.0608 .
## PC2:Block2       14.494     18.991   0.763   0.4485  
## PC2:Block3       12.109     15.918   0.761   0.4500  
## PC2:Block4        6.345     14.016   0.453   0.6525  
## sim:PC2:Block2  -15.002     19.514  -0.769   0.4452  
## sim:PC2:Block3  -12.259     16.323  -0.751   0.4557  
## sim:PC2:Block4   -6.217     14.448  -0.430   0.6686  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1939 on 57 degrees of freedom
## Multiple R-squared:  0.7738, Adjusted R-squared:  0.7143 
## F-statistic:    13 on 15 and 57 DF,  p-value: 2.73e-13
# Block sig
# PC2:TRT:Block significant
# PC2:sim:TRT:Block
# Marginal treatment effect 


# PC3 and simpson
simPC3<-(lm(RelativeFitness~PC3*sim*TRT*Block-PC3:sim:TRT:Block,RootFitAlpha))

anova(simPC3)# Marginal simpson
## Analysis of Variance Table
## 
## Response: RelativeFitness
##               Df Sum Sq Mean Sq F value    Pr(>F)    
## PC3            1 0.1472 0.14717  2.3049   0.13361    
## sim            1 0.1804 0.18043  2.8258   0.09735 .  
## TRT            1 0.0262 0.02620  0.4104   0.52393    
## Block          3 8.0786 2.69287 42.1739 1.634e-15 ***
## PC3:sim        1 0.0074 0.00740  0.1159   0.73453    
## PC3:TRT        1 0.0814 0.08144  1.2755   0.26271    
## sim:TRT        1 0.0150 0.01499  0.2348   0.62954    
## PC3:Block      3 0.2726 0.09087  1.4231   0.24361    
## sim:Block      3 0.0226 0.00754  0.1180   0.94923    
## TRT:Block      3 0.6226 0.20754  3.2503   0.02702 *  
## PC3:sim:TRT    1 0.2829 0.28292  4.4308   0.03899 *  
## PC3:sim:Block  3 0.3339 0.11131  1.7433   0.16639    
## PC3:TRT:Block  3 0.6259 0.20862  3.2673   0.02647 *  
## sim:TRT:Block  3 0.0250 0.00832  0.1303   0.94174    
## Residuals     68 4.3419 0.06385                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# significant Block
# TRT:Block significant
# PC3:sim:TRT significant
# PC3:TRT:Block 

summary(simPC3)# Marginal simpson
## 
## Call:
## lm(formula = RelativeFitness ~ PC3 * sim * TRT * Block - PC3:sim:TRT:Block, 
##     data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.66880 -0.08737 -0.00250  0.08177  0.85270 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)  
## (Intercept)         -14.2234    52.8303  -0.269   0.7886  
## PC3                  -8.8564    47.7361  -0.186   0.8534  
## sim                  15.1878    54.1353   0.281   0.7799  
## TRTInter             21.2688    54.0330   0.394   0.6951  
## Block2               17.5956    49.0732   0.359   0.7210  
## Block3               23.2894    56.4491   0.413   0.6812  
## Block4               15.3787    55.9463   0.275   0.7842  
## PC3:sim               9.1025    48.9063   0.186   0.8529  
## PC3:TRTInter         15.4803    44.7080   0.346   0.7302  
## sim:TRTInter        -21.7279    55.3673  -0.392   0.6960  
## PC3:Block2           -8.3836    34.2032  -0.245   0.8071  
## PC3:Block3          -40.6811    44.3192  -0.918   0.3619  
## PC3:Block4           26.3229    46.1503   0.570   0.5703  
## sim:Block2          -17.8500    50.3477  -0.355   0.7240  
## sim:Block3          -23.3692    57.8425  -0.404   0.6875  
## sim:Block4          -14.4641    57.4803  -0.252   0.8021  
## TRTInter:Block2     -21.6630    46.5786  -0.465   0.6434  
## TRTInter:Block3     -24.1818    54.0026  -0.448   0.6557  
## TRTInter:Block4     -32.6338    51.6022  -0.632   0.5292  
## PC3:sim:TRTInter    -15.9966    45.8066  -0.349   0.7280  
## PC3:sim:Block2        8.5154    35.0660   0.243   0.8089  
## PC3:sim:Block3       41.8959    45.3780   0.923   0.3591  
## PC3:sim:Block4      -28.1097    47.4568  -0.592   0.5556  
## PC3:TRTInter:Block2   0.3701     0.5201   0.711   0.4792  
## PC3:TRTInter:Block3  -0.5185     0.5207  -0.996   0.3229  
## PC3:TRTInter:Block4   0.9865     0.5572   1.770   0.0811 .
## sim:TRTInter:Block2  22.0978    47.7920   0.462   0.6453  
## sim:TRTInter:Block3  25.1259    55.3294   0.454   0.6512  
## sim:TRTInter:Block4  32.5984    52.9859   0.615   0.5405  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2527 on 68 degrees of freedom
## Multiple R-squared:  0.7118, Adjusted R-squared:  0.5931 
## F-statistic: 5.997 on 28 and 68 DF,  p-value: 8.503e-10
Model1a<-(lm(RelativeFitness~sim+PC3,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~sim+PC3,RootFitAlpha%>%filter(TRT!="Alone"))) 

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ sim + PC3, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4703 -0.3318 -0.2033  0.2180  1.3272 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  -1.8095    18.2024  -0.099    0.922
## sim           2.9122    18.7096   0.156    0.878
## PC3          -0.1684     0.2014  -0.836    0.413
## 
## Residual standard error: 0.5018 on 21 degrees of freedom
## Multiple R-squared:  0.03357,    Adjusted R-squared:  -0.05847 
## F-statistic: 0.3648 on 2 and 21 DF,  p-value: 0.6987
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ sim + PC3, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.46081 -0.35329 -0.01783  0.30299  1.15087 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.09479    4.90169  -0.835    0.406
## sim          5.23823    5.04630   1.038    0.303
## PC3         -0.01693    0.11992  -0.141    0.888
## 
## Residual standard error: 0.3651 on 70 degrees of freedom
## Multiple R-squared:  0.0152, Adjusted R-squared:  -0.01293 
## F-statistic: 0.5404 on 2 and 70 DF,  p-value: 0.5849
# PC4 and simpson
summary(lm(RelativeFitness~PC4+sim,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC4 + sim, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4724 -0.2934 -0.1654  0.1092  1.2992 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  -1.3237    18.0686  -0.073    0.942
## PC4           0.1564     0.1520   1.029    0.315
## sim           2.3418    18.5736   0.126    0.901
## 
## Residual standard error: 0.4977 on 21 degrees of freedom
## Multiple R-squared:  0.04931,    Adjusted R-squared:  -0.04123 
## F-statistic: 0.5447 on 2 and 21 DF,  p-value: 0.588
summary(lm(RelativeFitness~PC4+sim,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC4 + sim, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43274 -0.35392 -0.02619  0.29020  1.18353 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.59706    4.88686  -0.736    0.464
## PC4          0.05027    0.11832   0.425    0.672
## sim          4.73130    5.02536   0.941    0.350
## 
## Residual standard error: 0.3647 on 70 degrees of freedom
## Multiple R-squared:  0.01746,    Adjusted R-squared:  -0.01061 
## F-statistic: 0.6219 on 2 and 70 DF,  p-value: 0.5399
simPC4<-(lm(RelativeFitness~PC4*sim*TRT*Block-PC4:sim:TRT:Block,RootFitAlpha))

anova(simPC4)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##               Df Sum Sq Mean Sq F value    Pr(>F)    
## PC4            1 0.3109 0.31087  4.8750 0.0306243 *  
## sim            1 0.0917 0.09169  1.4379 0.2346391    
## TRT            1 0.0899 0.08986  1.4092 0.2393243    
## Block          3 7.7301 2.57670 40.4069  4.15e-15 ***
## PC4:sim        1 0.0331 0.03313  0.5195 0.4735387    
## PC4:TRT        1 0.0007 0.00067  0.0105 0.9187124    
## sim:TRT        1 0.0000 0.00000  0.0001 0.9933654    
## PC4:Block      3 0.6606 0.22020  3.4531 0.0211804 *  
## sim:Block      3 0.0705 0.02349  0.3683 0.7760682    
## TRT:Block      3 0.2466 0.08220  1.2891 0.2852120    
## PC4:sim:TRT    1 0.0119 0.01192  0.1869 0.6669063    
## PC4:sim:Block  3 0.0336 0.01119  0.1755 0.9126001    
## PC4:TRT:Block  3 0.1467 0.04889  0.7666 0.5166729    
## sim:TRT:Block  3 1.3012 0.43374  6.8018 0.0004456 ***
## Residuals     68 4.3363 0.06377                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant PC4
# Significant Block
# Significant PC4:Block
# Significant sim:TRT:Block



# Inv Simp and PC1
InsimPC1<-(lm(RelativeFitness~PC1*InvSimp*TRT*Block-PC1:InvSimp:TRT:Block,RootFitAlpha))

anova(InsimPC1)# Significant InvSimp
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## PC1                1 0.1572 0.15720  2.6049   0.11117    
## InvSimp            1 0.3077 0.30773  5.0993   0.02715 *  
## TRT                1 0.0280 0.02802  0.4643   0.49792    
## Block              3 7.7693 2.58976 42.9143 1.114e-15 ***
## PC1:InvSimp        1 0.0200 0.01995  0.3306   0.56720    
## PC1:TRT            1 0.0072 0.00720  0.1194   0.73078    
## InvSimp:TRT        1 0.0112 0.01125  0.1864   0.66730    
## PC1:Block          3 0.6440 0.21467  3.5573   0.01870 *  
## InvSimp:Block      3 0.0069 0.00232  0.0384   0.98987    
## TRT:Block          3 0.1715 0.05716  0.9472   0.42282    
## PC1:InvSimp:TRT    1 0.0105 0.01045  0.1732   0.67860    
## PC1:InvSimp:Block  3 0.1621 0.05403  0.8952   0.44823    
## PC1:TRT:Block      3 1.5731 0.52437  8.6892 5.861e-05 ***
## InvSimp:TRT:Block  3 0.0913 0.03044  0.5044   0.68051    
## Residuals         68 4.1036 0.06035                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant Block


# Inv Simp and PC2
InsimPC2<-(lm(RelativeFitness~PC2*InvSimp*TRT*Block-PC2:InvSimp:TRT:Block,RootFitAlpha))

anova(InsimPC2)# Significant InvSimp
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## PC2                1 0.0335 0.03349  0.5031  0.480569    
## InvSimp            1 0.3449 0.34489  5.1808  0.025991 *  
## TRT                1 0.1493 0.14929  2.2425  0.138889    
## Block              3 7.7050 2.56833 38.5804 1.118e-14 ***
## PC2:InvSimp        1 0.0066 0.00664  0.0998  0.753045    
## PC2:TRT            1 0.0374 0.03743  0.5622  0.455949    
## InvSimp:TRT        1 0.0012 0.00123  0.0184  0.892412    
## PC2:Block          3 0.1192 0.03972  0.5966  0.619390    
## InvSimp:Block      3 0.0322 0.01072  0.1610  0.922207    
## TRT:Block          3 0.2806 0.09352  1.4048  0.248918    
## PC2:InvSimp:TRT    1 0.0000 0.00003  0.0004  0.983368    
## PC2:InvSimp:Block  3 0.2563 0.08543  1.2833  0.287137    
## PC2:TRT:Block      3 1.1819 0.39397  5.9180  0.001196 ** 
## InvSimp:TRT:Block  3 0.3888 0.12960  1.9467  0.130301    
## Residuals         68 4.5268 0.06657                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant Block# Significant Inverse simpson 
# Significant Block
# Significant PC2:TRT:Block 
# Significant PC2:InvSimp:TRT:Block 
# Marginal InvSimp:TRT:Block



# PC3 and Inv Simpson
InsimPC3<-(lm(RelativeFitness~PC3*InvSimp*TRT*Block-PC3:InvSimp:TRT:Block,RootFitAlpha))
anova(lm(RelativeFitness~PC3*InvSimp*TRT+Block,RootFitAlpha))
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                 Df Sum Sq Mean Sq F value    Pr(>F)    
## PC3              1 0.1472 0.14717  2.0545   0.15539    
## InvSimp          1 0.4312 0.43121  6.0196   0.01617 *  
## TRT              1 0.0110 0.01102  0.1539   0.69584    
## Block            3 7.8431 2.61437 36.4961 2.607e-15 ***
## PC3:InvSimp      1 0.0296 0.02959  0.4131   0.52212    
## PC3:TRT          1 0.0810 0.08095  1.1301   0.29073    
## InvSimp:TRT      1 0.0118 0.01182  0.1649   0.68565    
## PC3:InvSimp:TRT  1 0.3483 0.34828  4.8619   0.03012 *  
## Residuals       86 6.1605 0.07163                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(InsimPC3)# Significant InvSimp
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## PC3                1 0.1472 0.14717  2.2663   0.13685    
## InvSimp            1 0.4312 0.43121  6.6403   0.01214 *  
## TRT                1 0.0110 0.01102  0.1697   0.68165    
## Block              3 7.8431 2.61437 40.2593 4.491e-15 ***
## PC3:InvSimp        1 0.0296 0.02959  0.4557   0.50194    
## PC3:TRT            1 0.0810 0.08095  1.2466   0.26812    
## InvSimp:TRT        1 0.0118 0.01182  0.1820   0.67105    
## PC3:Block          3 0.2839 0.09463  1.4572   0.23398    
## InvSimp:Block      3 0.0250 0.00832  0.1282   0.94307    
## TRT:Block          3 0.6251 0.20835  3.2085   0.02841 *  
## PC3:InvSimp:TRT    1 0.3230 0.32301  4.9740   0.02903 *  
## PC3:InvSimp:Block  3 0.1879 0.06263  0.9645   0.41463    
## PC3:TRT:Block      3 0.6276 0.20921  3.2216   0.02796 *  
## InvSimp:TRT:Block  3 0.0206 0.00686  0.1056   0.95654    
## Residuals         68 4.4158 0.06494                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Plot marginal means

# Within treatment
Model1a<-(lm(RelativeFitness~InvSimp+PC3,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~InvSimp+PC3,RootFitAlpha%>%filter(TRT!="Alone"))) 

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimp + PC3, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4887 -0.3279 -0.2033  0.2446  1.3108 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.807557   0.571110   1.414    0.172
## InvSimp      0.005734   0.014510   0.395    0.697
## PC3         -0.171933   0.200835  -0.856    0.402
## 
## Residual standard error: 0.5003 on 21 degrees of freedom
## Multiple R-squared:  0.0396, Adjusted R-squared:  -0.05187 
## F-statistic: 0.4329 on 2 and 21 DF,  p-value: 0.6543
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimp + PC3, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.48730 -0.33829 -0.00749  0.23481  1.14643 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.743057   0.164404    4.52 2.46e-05 ***
## InvSimp      0.006644   0.004206    1.58    0.119    
## PC3         -0.037131   0.119838   -0.31    0.758    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3615 on 70 degrees of freedom
## Multiple R-squared:  0.03447,    Adjusted R-squared:  0.006882 
## F-statistic: 1.249 on 2 and 70 DF,  p-value: 0.293
# Inv simp and PC4
InsimPC4<-(lm(RelativeFitness~PC4*InvSimp*TRT*Block-PC4:InvSimp:TRT:Block,RootFitAlpha))

anova(InsimPC4)# Significant InvSimp
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## PC4                1 0.3109 0.31087  4.6388 0.034805 *  
## InvSimp            1 0.2915 0.29149  4.3495 0.040775 *  
## TRT                1 0.0768 0.07676  1.1455 0.288284    
## Block              3 7.5424 2.51413 37.5154 2.02e-14 ***
## PC4:InvSimp        1 0.0157 0.01565  0.2335 0.630460    
## PC4:TRT            1 0.0009 0.00094  0.0140 0.906228    
## InvSimp:TRT        1 0.0000 0.00001  0.0001 0.991107    
## PC4:Block          3 0.6935 0.23118  3.4496 0.021270 *  
## InvSimp:Block      3 0.0722 0.02405  0.3589 0.782836    
## TRT:Block          3 0.3240 0.10800  1.6115 0.194776    
## PC4:InvSimp:TRT    1 0.0000 0.00004  0.0006 0.980912    
## PC4:InvSimp:Block  3 0.0566 0.01886  0.2814 0.838666    
## PC4:TRT:Block      3 0.1333 0.04443  0.6630 0.577670    
## InvSimp:TRT:Block  3 0.9889 0.32963  4.9187 0.003757 ** 
## Residuals         68 4.5571 0.06702                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant PC4
# Significant InvSimp
# Significant Block
# Significant PC4:Block
# Significant InvSimp:TRT:Block


# Even and PC1
EvenPC1<-(lm(RelativeFitness~PC1*even*TRT*Block-PC1:even:TRT:Block,RootFitAlpha))

anova(EvenPC1)# Marginal PC1:even:Block
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC1             1 0.1572 0.15720  2.5901 0.1121697    
## even            1 0.9609 0.96094 15.8329 0.0001705 ***
## TRT             1 0.0945 0.09446  1.5564 0.2164694    
## Block           3 7.0450 2.34833 38.6921 1.051e-14 ***
## PC1:even        1 0.0110 0.01097  0.1808 0.6720186    
## PC1:TRT         1 0.0073 0.00727  0.1197 0.7304251    
## even:TRT        1 0.0291 0.02912  0.4799 0.4908485    
## PC1:Block       3 0.4770 0.15899  2.6196 0.0577970 .  
## even:Block      3 0.2369 0.07898  1.3013 0.2811621    
## TRT:Block       3 0.2228 0.07427  1.2237 0.3078255    
## PC1:even:TRT    1 0.0503 0.05032  0.8290 0.3657653    
## PC1:even:Block  3 0.4498 0.14993  2.4703 0.0692345 .  
## PC1:TRT:Block   3 0.9172 0.30572  5.0372 0.0032749 ** 
## even:TRT:Block  3 0.2776 0.09254  1.5247 0.2159789    
## Residuals      68 4.1271 0.06069                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant PC1:TRT:Block 
# Significant PC1:Block 
# Significant even 
# Significant Block




# Even and PC2
EvenPC2<-(lm(RelativeFitness~PC2*even*TRT*Block-PC2:even:TRT:Block,RootFitAlpha))

anova(EvenPC2)# Significant even
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC2             1 0.0335 0.03349  0.4791 0.4911911    
## even            1 0.9467 0.94674 13.5430 0.0004625 ***
## TRT             1 0.2802 0.28024  4.0088 0.0492548 *  
## Block           3 6.9740 2.32466 33.2541 2.399e-13 ***
## PC2:even        1 0.0042 0.00419  0.0599 0.8073384    
## PC2:TRT         1 0.0392 0.03923  0.5612 0.4563424    
## even:TRT        1 0.0224 0.02240  0.3204 0.5732100    
## PC2:Block       3 0.0807 0.02688  0.3846 0.7644415    
## even:Block      3 0.2732 0.09107  1.3028 0.2806703    
## TRT:Block       3 0.3189 0.10629  1.5205 0.2170625    
## PC2:even:TRT    1 0.0049 0.00488  0.0698 0.7924102    
## PC2:even:Block  3 0.2932 0.09772  1.3979 0.2509731    
## PC2:TRT:Block   3 0.9836 0.32787  4.6901 0.0049017 ** 
## even:TRT:Block  3 0.0554 0.01846  0.2641 0.8510158    
## Residuals      68 4.7536 0.06991                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant Treatment
# Significant Block
# Significant PC2:TRT:Block
# Significant PC2:even:TRT:Block



# Even and PC3
EvenPC3<-(lm(RelativeFitness~PC3*even*TRT*Block-PC3:even:TRT:Block,RootFitAlpha))

anova(EvenPC3)# Significant even
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC3             1 0.1472 0.14717  2.4716 0.1205639    
## even            1 1.0146 1.01457 17.0387 0.0001022 ***
## TRT             1 0.0887 0.08870  1.4896 0.2264958    
## Block           3 7.1871 2.39570 40.2335 4.554e-15 ***
## PC3:even        1 0.0068 0.00678  0.1139 0.7368152    
## PC3:TRT         1 0.0789 0.07894  1.3257 0.2536128    
## even:TRT        1 0.0032 0.00319  0.0535 0.8177823    
## PC3:Block       3 0.3195 0.10650  1.7885 0.1575917    
## even:Block      3 0.3035 0.10115  1.6987 0.1754996    
## TRT:Block       3 0.6117 0.20389  3.4241 0.0219302 *  
## PC3:even:TRT    1 0.1565 0.15650  2.6283 0.1096001    
## PC3:even:Block  3 0.5204 0.17347  2.9133 0.0405360 *  
## PC3:TRT:Block   3 0.4101 0.13670  2.2957 0.0855056 .  
## even:TRT:Block  3 0.1666 0.05552  0.9324 0.4299097    
## Residuals      68 4.0491 0.05954                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant Block
# Significant TRT:Block
# Significant PC3:even:Block
# Marginal PC3:TRT:Block  

# Within treatment
Model1a<-(lm(RelativeFitness~even+PC3,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~even+PC3,RootFitAlpha%>%filter(TRT!="Alone"))) 

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ even + PC3, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4972 -0.3149 -0.1819  0.1996  1.2059 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)    3.7658     2.2808   1.651    0.114
## even        -271.0769   224.9026  -1.205    0.241
## PC3           -0.1177     0.1994  -0.590    0.562
## 
## Residual standard error: 0.4856 on 21 degrees of freedom
## Multiple R-squared:  0.09506,    Adjusted R-squared:  0.008876 
## F-statistic: 1.103 on 2 and 21 DF,  p-value: 0.3504
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ even + PC3, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57479 -0.27236 -0.02728  0.22361  1.11679 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)    3.18830    0.95158   3.351   0.0013 **
## even        -211.15458   91.43659  -2.309   0.0239 * 
## PC3           -0.01613    0.11479  -0.140   0.8887   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3547 on 70 degrees of freedom
## Multiple R-squared:  0.07083,    Adjusted R-squared:  0.04429 
## F-statistic: 2.668 on 2 and 70 DF,  p-value: 0.07643
# Even and PC4
EvenPC4<-(lm(RelativeFitness~PC4*even*TRT*Block-PC4:even:TRT:Block,RootFitAlpha))

anova(EvenPC4)# Significant even
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## PC4             1 0.3109 0.31087  4.2821  0.042319 *  
## even            1 0.8223 0.82234 11.3272  0.001259 ** 
## TRT             1 0.1823 0.18226  2.5105  0.117730    
## Block           3 6.9100 2.30333 31.7271 6.092e-13 ***
## PC4:even        1 0.0743 0.07430  1.0235  0.315286    
## PC4:TRT         1 0.0021 0.00208  0.0287  0.865948    
## even:TRT        1 0.0513 0.05127  0.7063  0.403628    
## PC4:Block       3 0.6478 0.21594  2.9745  0.037651 *  
## even:Block      3 0.1242 0.04140  0.5703  0.636507    
## TRT:Block       3 0.4215 0.14049  1.9352  0.132121    
## PC4:even:TRT    1 0.0004 0.00036  0.0049  0.944195    
## PC4:even:Block  3 0.1952 0.06506  0.8962  0.447761    
## PC4:TRT:Block   3 0.0771 0.02570  0.3539  0.786425    
## even:TRT:Block  3 0.3077 0.10258  1.4130  0.246537    
## Residuals      68 4.9367 0.07260                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant PC4
# Marginal TRT
# Significant Block
# PC4:Block
# Marginal Block:TRT
# Significant PC4:even:TRT:Block

# Within treatment
Model1a<-(lm(RelativeFitness~even*PC4,RootFitAlpha%>%filter(TRT=="Alone")))
Model1c<-(lm(RelativeFitness~even*PC4,RootFitAlpha%>%filter(TRT!="Alone"))) 

summary(Model1a)
## 
## Call:
## lm(formula = RelativeFitness ~ even * PC4, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5169 -0.2779 -0.1566  0.1333  1.2017 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)    3.6016     2.4358   1.479    0.155
## even        -259.5063   237.7250  -1.092    0.288
## PC4            0.5432     3.7641   0.144    0.887
## even:PC4     -40.6631   367.1100  -0.111    0.913
## 
## Residual standard error: 0.4931 on 20 degrees of freedom
## Multiple R-squared:  0.1112, Adjusted R-squared:  -0.02212 
## F-statistic: 0.8341 on 3 and 20 DF,  p-value: 0.4909
summary(Model1c)
## 
## Call:
## lm(formula = RelativeFitness ~ even * PC4, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53841 -0.26938 -0.02512  0.22753  1.14471 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept)    3.2467     1.1027   2.944  0.00441 **
## even        -216.7975   106.6981  -2.032  0.04602 * 
## PC4            0.5779     2.8706   0.201  0.84105   
## even:PC4     -53.3633   275.2950  -0.194  0.84687   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3571 on 69 degrees of freedom
## Multiple R-squared:  0.07156,    Adjusted R-squared:  0.03119 
## F-statistic: 1.773 on 3 and 69 DF,  p-value: 0.1605
#RootFitAlpha<-merge(SizePurp,RootFitAlpha)

library(interactions)
library(jtools)
## 
## Attaching package: 'jtools'
## The following object is masked from 'package:Hmisc':
## 
##     %nin%
# Scale the microbial variables
RootFitAlpha$richScaled<-scale(RootFitAlpha$rich)
RootFitAlpha$SimScaled<-scale(RootFitAlpha$sim)
RootFitAlpha$InvSimScaled<-scale(RootFitAlpha$InvSimp)
RootFitAlpha$EvenScaled<-scale(RootFitAlpha$even)


# Phenotypic selection UNIVARIATE
summary(lm(RelativeFitness~PC1,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC1, data = RootFitAlpha %>% filter(TRT == 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.65460 -0.26942 -0.09513  0.25049  1.09128 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.04144    0.14836   7.020 4.81e-07 ***
## PC1          0.09390    0.08143   1.153    0.261    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4843 on 22 degrees of freedom
## Multiple R-squared:  0.057,  Adjusted R-squared:  0.01413 
## F-statistic:  1.33 on 1 and 22 DF,  p-value: 0.2612
summary(lm(RelativeFitness~PC1,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC1, data = RootFitAlpha %>% filter(TRT != 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42418 -0.34678 -0.01929  0.32625  1.17732 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.99647    0.04299  23.177   <2e-16 ***
## PC1         -0.02824    0.05666  -0.498     0.62    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3647 on 71 degrees of freedom
## Multiple R-squared:  0.003485,   Adjusted R-squared:  -0.01055 
## F-statistic: 0.2483 on 1 and 71 DF,  p-value: 0.6198
summary(lm(RelativeFitness~PC1,RootFitAlpha)) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC1, data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55731 -0.34752 -0.07482  0.25951  1.18858 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.98401    0.04142  23.757   <2e-16 ***
## PC1          0.03701    0.03698   1.001    0.319    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3961 on 95 degrees of freedom
## Multiple R-squared:  0.01044,    Adjusted R-squared:  1.908e-05 
## F-statistic: 1.002 on 1 and 95 DF,  p-value: 0.3194
summary(lm(RelativeFitness~PC2,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC2, data = RootFitAlpha %>% filter(TRT == 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.48811 -0.35822 -0.09721  0.15910  1.28637 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.90207    0.10971   8.222 3.74e-08 ***
## PC2         -0.02241    0.07852  -0.285    0.778    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4978 on 22 degrees of freedom
## Multiple R-squared:  0.00369,    Adjusted R-squared:  -0.0416 
## F-statistic: 0.08148 on 1 and 22 DF,  p-value: 0.778
summary(lm(RelativeFitness~PC2,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC2, data = RootFitAlpha %>% filter(TRT != 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44699 -0.34284 -0.07087  0.31496  1.21855 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.99395    0.04258  23.344   <2e-16 ***
## PC2         -0.05703    0.07374  -0.773    0.442    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3638 on 71 degrees of freedom
## Multiple R-squared:  0.008356,   Adjusted R-squared:  -0.005611 
## F-statistic: 0.5983 on 1 and 71 DF,  p-value: 0.4418
summary(lm(RelativeFitness~PC2,RootFitAlpha)) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC2, data = RootFitAlpha)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5567 -0.3417 -0.0957  0.3036  1.2174 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.97126    0.04086   23.77   <2e-16 ***
## PC2         -0.02194    0.04769   -0.46    0.647    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3978 on 95 degrees of freedom
## Multiple R-squared:  0.002223,   Adjusted R-squared:  -0.00828 
## F-statistic: 0.2117 on 1 and 95 DF,  p-value: 0.6465
summary(lm(RelativeFitness~PC4,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC4, data = RootFitAlpha %>% filter(TRT == 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.47062 -0.29680 -0.16660  0.09031  1.30907 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.9543     0.1064   8.971 8.37e-09 ***
## PC4           0.1573     0.1484   1.060    0.301    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4865 on 22 degrees of freedom
## Multiple R-squared:  0.04859,    Adjusted R-squared:  0.005349 
## F-statistic: 1.124 on 1 and 22 DF,  p-value: 0.3006
summary(lm(RelativeFitness~PC4,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC4, data = RootFitAlpha %>% filter(TRT != 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.41271 -0.35334 -0.02464  0.28524  1.19788 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.00364    0.04565  21.985   <2e-16 ***
## PC4          0.06965    0.11642   0.598    0.552    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3644 on 71 degrees of freedom
## Multiple R-squared:  0.005016,   Adjusted R-squared:  -0.008998 
## F-statistic: 0.358 on 1 and 71 DF,  p-value: 0.5515
summary(lm(RelativeFitness~PC4,RootFitAlpha)) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC4, data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.49562 -0.32506 -0.09444  0.27099  1.25420 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.99474    0.04259  23.357   <2e-16 ***
## PC4          0.12228    0.08642   1.415     0.16    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3941 on 95 degrees of freedom
## Multiple R-squared:  0.02064,    Adjusted R-squared:  0.01033 
## F-statistic: 2.002 on 1 and 95 DF,  p-value: 0.1604
summary(lm(RelativeFitness~PC3,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC3, data = RootFitAlpha %>% filter(TRT == 
##     "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4600 -0.3594 -0.2105  0.1988  1.3395 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.0236     0.1623   6.308 2.39e-06 ***
## PC3          -0.1691     0.1968  -0.859      0.4    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4906 on 22 degrees of freedom
## Multiple R-squared:  0.03246,    Adjusted R-squared:  -0.01152 
## F-statistic: 0.738 on 1 and 22 DF,  p-value: 0.3996
summary(lm(RelativeFitness~PC3,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC3, data = RootFitAlpha %>% filter(TRT != 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42122 -0.35018 -0.02809  0.32572  1.18028 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.993125   0.044859  22.139   <2e-16 ***
## PC3         0.006728   0.117799   0.057    0.955    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3653 on 71 degrees of freedom
## Multiple R-squared:  4.594e-05,  Adjusted R-squared:  -0.01404 
## F-statistic: 0.003262 on 1 and 71 DF,  p-value: 0.9546
summary(lm(RelativeFitness~PC3,RootFitAlpha)) 
## 
## Call:
## lm(formula = RelativeFitness ~ PC3, data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.49194 -0.35042 -0.07094  0.24924  1.28521 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.99481    0.04557  21.832   <2e-16 ***
## PC3         -0.08377    0.08653  -0.968    0.335    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3963 on 95 degrees of freedom
## Multiple R-squared:  0.00977,    Adjusted R-squared:  -0.0006537 
## F-statistic: 0.9373 on 1 and 95 DF,  p-value: 0.3354
  # Alpha diversity
summary(lm(RelativeFitness~EvenScaled,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ EvenScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5431 -0.3424 -0.1684  0.2188  1.1555 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.88137    0.10043   8.776 1.23e-08 ***
## EvenScaled  -0.13811    0.09981  -1.384     0.18    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4784 on 22 degrees of freedom
## Multiple R-squared:  0.08006,    Adjusted R-squared:  0.03825 
## F-statistic: 1.915 on 1 and 22 DF,  p-value: 0.1803
summary(lm(RelativeFitness~EvenScaled,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ EvenScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55993 -0.26890 -0.02759  0.21735  1.13118 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.00140    0.04135  24.219   <2e-16 ***
## EvenScaled  -0.09687    0.04172  -2.322   0.0231 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3522 on 71 degrees of freedom
## Multiple R-squared:  0.07057,    Adjusted R-squared:  0.05748 
## F-statistic: 5.391 on 1 and 71 DF,  p-value: 0.02311
anova(lm(RelativeFitness~EvenScaled*TRT,RootFitAlpha))
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df  Sum Sq Mean Sq F value  Pr(>F)  
## EvenScaled      1  0.9647 0.96469  6.4818 0.01254 *
## TRT             1  0.2283 0.22826  1.5337 0.21868  
## EvenScaled:TRT  1  0.0295 0.02954  0.1985 0.65700  
## Residuals      93 13.8412 0.14883                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(RelativeFitness~SimScaled,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ SimScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4787 -0.3672 -0.1385  0.1897  1.2711 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.91175    0.10245   8.899 9.64e-09 ***
## SimScaled    0.02616    0.14886   0.176    0.862    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4984 on 22 degrees of freedom
## Multiple R-squared:  0.001402,   Adjusted R-squared:  -0.04399 
## F-statistic: 0.03089 on 1 and 22 DF,  p-value: 0.8621
summary(lm(RelativeFitness~SimScaled,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ SimScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44546 -0.35291 -0.02388  0.30147  1.16595 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.99500    0.04245  23.439   <2e-16 ***
## SimScaled    0.04089    0.03943   1.037    0.303    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3626 on 71 degrees of freedom
## Multiple R-squared:  0.01492,    Adjusted R-squared:  0.00105 
## F-statistic: 1.076 on 1 and 71 DF,  p-value: 0.3032
anova(lm(RelativeFitness~SimScaled*TRT,RootFitAlpha))
## Analysis of Variance Table
## 
## Response: RelativeFitness
##               Df  Sum Sq  Mean Sq F value Pr(>F)
## SimScaled      1  0.1346 0.134644  0.8461 0.3600
## TRT            1  0.1280 0.127955  0.8041 0.3722
## SimScaled:TRT  1  0.0021 0.002147  0.0135 0.9078
## Residuals     93 14.7989 0.159128
summary(lm(RelativeFitness~InvSimScaled,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4985 -0.3568 -0.1458  0.2132  1.2573 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.9155     0.1016   9.012 7.74e-09 ***
## InvSimScaled   0.0512     0.1396   0.367    0.717    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4972 on 22 degrees of freedom
## Multiple R-squared:  0.006081,   Adjusted R-squared:  -0.0391 
## F-statistic: 0.1346 on 1 and 22 DF,  p-value: 0.7172
summary(lm(RelativeFitness~InvSimScaled,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.48452 -0.34071 -0.03188  0.25939  1.17882 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.99326    0.04205   23.62   <2e-16 ***
## InvSimScaled  0.06141    0.03936    1.56    0.123    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3592 on 71 degrees of freedom
## Multiple R-squared:  0.03314,    Adjusted R-squared:  0.01953 
## F-statistic: 2.434 on 1 and 71 DF,  p-value: 0.1232
anova(lm(RelativeFitness~InvSimScaled*TRT,RootFitAlpha))
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                  Df  Sum Sq Mean Sq F value Pr(>F)
## InvSimScaled      1  0.3534 0.35338  2.2509 0.1369
## TRT               1  0.1085 0.10847  0.6909 0.4080
## InvSimScaled:TRT  1  0.0011 0.00115  0.0073 0.9320
## Residuals        93 14.6007 0.15700
summary(lm(RelativeFitness~rich,RootFitAlpha%>%filter(TRT=="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ rich, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5235 -0.3408 -0.1732  0.2074  1.1566 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.784092   1.427398  -0.549    0.588
## rich         0.003734   0.003132   1.192    0.246
## 
## Residual standard error: 0.4834 on 22 degrees of freedom
## Multiple R-squared:  0.06071,    Adjusted R-squared:  0.01801 
## F-statistic: 1.422 on 1 and 22 DF,  p-value: 0.2458
summary(lm(RelativeFitness~rich,RootFitAlpha%>%filter(TRT!="Alone"))) 
## 
## Call:
## lm(formula = RelativeFitness ~ rich, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53579 -0.29469 -0.01234  0.22797  1.13305 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.255525   0.572115  -0.447   0.6565  
## rich         0.002806   0.001281   2.190   0.0318 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3536 on 71 degrees of freedom
## Multiple R-squared:  0.06326,    Adjusted R-squared:  0.05006 
## F-statistic: 4.794 on 1 and 71 DF,  p-value: 0.03184
summary(lm(RelativeFitness~rich,RootFitAlpha)) # Significant
## 
## Call:
## lm(formula = RelativeFitness ~ rich, data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.59124 -0.31236 -0.00207  0.23594  1.15892 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.299358   0.545241  -0.549   0.5843  
## rich         0.002845   0.001215   2.342   0.0213 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3872 on 95 degrees of freedom
## Multiple R-squared:  0.05457,    Adjusted R-squared:  0.04462 
## F-statistic: 5.483 on 1 and 95 DF,  p-value: 0.02129
anova(lm(RelativeFitness~rich*TRT,RootFitAlpha))
## Analysis of Variance Table
## 
## Response: RelativeFitness
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## rich       1  0.8220 0.82204  5.4543 0.02167 *
## TRT        1  0.2096 0.20957  1.3905 0.24133  
## rich:TRT   1  0.0156 0.01563  0.1037 0.74812  
## Residuals 93 14.0164 0.15071                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# ANCOVA MUltivariate Selection

# ANCOVA<-(lm(RelativeFitness~TRT+Block+TRT:Block+PC1*Block+PC2*Block+PC3*Block+PC4*Block+richScaled*Block+InvSimScaled*Block+EvenScaled*Block+PC1*TRT*Block+PC2*TRT*Block+PC3*TRT*Block+PC4*TRT*Block+richScaled*TRT*Block+InvSimScaled*TRT*Block+EvenScaled*TRT*Block,RootFitAlpha)) # Full model w Trt by Block interactions per vars



ANCOVA<-(lm(RelativeFitness~TRT+Block+TRT:Block+PC1*TRT+PC2*TRT+PC3*TRT+PC4*TRT+richScaled*TRT+InvSimScaled*TRT+EvenScaled*TRT+PC1*Block+PC2*Block+PC3*Block+PC4*Block+richScaled*Block+InvSimScaled*Block+EvenScaled*Block,RootFitAlpha)) # Full model reported

# Step wise backward regression
library(MASS)

step<-stepAIC(ANCOVA,direction = "backward",trace=FALSE)
step$anova
## Stepwise Model Path 
## Analysis of Deviance Table
## 
## Initial Model:
## RelativeFitness ~ TRT + Block + TRT:Block + PC1 * TRT + PC2 * 
##     TRT + PC3 * TRT + PC4 * TRT + richScaled * TRT + InvSimScaled * 
##     TRT + EvenScaled * TRT + PC1 * Block + PC2 * Block + PC3 * 
##     Block + PC4 * Block + richScaled * Block + InvSimScaled * 
##     Block + EvenScaled * Block
## 
## Final Model:
## RelativeFitness ~ TRT + Block + PC1 + PC2 + PC3 + PC4 + richScaled + 
##     InvSimScaled + EvenScaled + TRT:Block + TRT:PC1 + TRT:PC3 + 
##     TRT:richScaled + TRT:EvenScaled + Block:PC1 + Block:PC2 + 
##     Block:PC3 + Block:PC4 + Block:richScaled + Block:InvSimScaled + 
##     Block:EvenScaled
## 
## 
##                 Step Df    Deviance Resid. Df Resid. Dev       AIC
## 1                                          54   3.404728 -238.9059
## 2          - TRT:PC4  1 0.004318070        55   3.409046 -240.7830
## 3 - TRT:InvSimScaled  1 0.004653243        56   3.413700 -242.6507
## 4          - TRT:PC2  1 0.020806204        57   3.434506 -244.0613
model<-lm(RelativeFitness ~ TRT + Block + PC1 + PC2 + PC3 + PC4 + richScaled + 
    InvSimScaled + EvenScaled + TRT:Block + TRT:PC1 + TRT:PC3 + 
    TRT:richScaled + TRT:EvenScaled + Block:PC1 + Block:PC2 + 
    Block:PC3 + Block:PC4 + Block:richScaled + Block:InvSimScaled + 
    Block:EvenScaled,RootFitAlpha
)


# anova(model) # Type I sum of squres--sequence order matters, interactions not accounted

car::Anova(model,type="III") # Report the type three sums of squares~
## Anova Table (Type III tests)
## 
## Response: RelativeFitness
##                    Sum Sq Df F value   Pr(>F)   
## (Intercept)        0.2225  1  3.6920 0.059678 . 
## TRT                0.0063  1  0.1040 0.748271   
## Block              0.8159  3  4.5139 0.006563 **
## PC1                0.0193  1  0.3197 0.574012   
## PC2                0.0051  1  0.0849 0.771792   
## PC3                0.0000  1  0.0005 0.982541   
## PC4                0.0883  1  1.4647 0.231172   
## richScaled         0.0449  1  0.7456 0.391506   
## InvSimScaled       0.0000  1  0.0000 0.998091   
## EvenScaled         0.0057  1  0.0945 0.759674   
## TRT:Block          0.2663  3  1.4733 0.231453   
## TRT:PC1            0.1905  1  3.1620 0.080705 . 
## TRT:PC3            0.1328  1  2.2043 0.143134   
## TRT:richScaled     0.4641  1  7.7023 0.007446 **
## TRT:EvenScaled     0.1964  1  3.2599 0.076274 . 
## Block:PC1          0.9067  3  5.0159 0.003727 **
## Block:PC2          0.2339  3  1.2942 0.285204   
## Block:PC3          0.2449  3  1.3546 0.265867   
## Block:PC4          1.1098  3  6.1395 0.001084 **
## Block:richScaled   0.4936  3  2.7309 0.052151 . 
## Block:InvSimScaled 0.4500  3  2.4892 0.069456 . 
## Block:EvenScaled   0.4861  3  2.6889 0.054807 . 
## Residuals          3.4345 57                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(model)
## 
## Call:
## lm(formula = RelativeFitness ~ TRT + Block + PC1 + PC2 + PC3 + 
##     PC4 + richScaled + InvSimScaled + EvenScaled + TRT:Block + 
##     TRT:PC1 + TRT:PC3 + TRT:richScaled + TRT:EvenScaled + Block:PC1 + 
##     Block:PC2 + Block:PC3 + Block:PC4 + Block:richScaled + Block:InvSimScaled + 
##     Block:EvenScaled, data = RootFitAlpha)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.45989 -0.10122  0.01903  0.08367  0.54005 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)   
## (Intercept)          0.5644084  0.2937384   1.921  0.05968 . 
## TRTInter             0.0976872  0.3029271   0.322  0.74827   
## Block2              -0.0333271  0.3315102  -0.101  0.92028   
## Block3               0.9303123  0.3620020   2.570  0.01281 * 
## Block4               0.6503006  0.3187389   2.040  0.04597 * 
## PC1                 -0.0589637  0.1042843  -0.565  0.57401   
## PC2                  0.0251966  0.0864631   0.291  0.77179   
## PC3                 -0.0048579  0.2210150  -0.022  0.98254   
## PC4                  0.2866935  0.2368849   1.210  0.23117   
## richScaled           0.3804680  0.4406342   0.863  0.39151   
## InvSimScaled        -0.0005248  0.2183718  -0.002  0.99809   
## EvenScaled           0.1056800  0.3438079   0.307  0.75967   
## TRTInter:Block2      0.2105048  0.3554575   0.592  0.55605   
## TRTInter:Block3     -0.1818244  0.3737280  -0.487  0.62847   
## TRTInter:Block4     -0.3291469  0.3338717  -0.986  0.32837   
## TRTInter:PC1         0.1766822  0.0993601   1.778  0.08070 . 
## TRTInter:PC3         0.2379503  0.1602688   1.485  0.14313   
## TRTInter:richScaled -0.7041574  0.2537230  -2.775  0.00745 **
## TRTInter:EvenScaled -0.4258074  0.2358355  -1.806  0.07627 . 
## Block2:PC1          -0.1922776  0.1475096  -1.303  0.19765   
## Block3:PC1           0.1606998  0.1310276   1.226  0.22507   
## Block4:PC1          -0.2092075  0.1357794  -1.541  0.12890   
## Block2:PC2          -0.1881294  0.1208516  -1.557  0.12508   
## Block3:PC2           0.0233480  0.1409315   0.166  0.86900   
## Block4:PC2          -0.1370329  0.1153875  -1.188  0.23992   
## Block2:PC3          -0.2827958  0.2791032  -1.013  0.31523   
## Block3:PC3          -0.3696423  0.2752071  -1.343  0.18455   
## Block4:PC3          -0.4885016  0.2479188  -1.970  0.05366 . 
## Block2:PC4          -0.0781221  0.2666283  -0.293  0.77059   
## Block3:PC4          -0.8631692  0.2843812  -3.035  0.00362 **
## Block4:PC4          -0.4061012  0.2680725  -1.515  0.13533   
## Block2:richScaled    0.1019838  0.5995899   0.170  0.86554   
## Block3:richScaled   -0.3168643  0.5909213  -0.536  0.59389   
## Block4:richScaled    1.1663541  0.4998220   2.334  0.02317 * 
## Block2:InvSimScaled  0.0560490  0.3074563   0.182  0.85599   
## Block3:InvSimScaled  0.2484597  0.3004664   0.827  0.41173   
## Block4:InvSimScaled -0.5537672  0.2996460  -1.848  0.06978 . 
## Block2:EvenScaled    0.1496708  0.4204558   0.356  0.72318   
## Block3:EvenScaled   -0.1359585  0.4642850  -0.293  0.77071   
## Block4:EvenScaled    0.9890849  0.3924176   2.520  0.01454 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2455 on 57 degrees of freedom
## Multiple R-squared:  0.772,  Adjusted R-squared:  0.616 
## F-statistic: 4.949 on 39 and 57 DF,  p-value: 2.921e-08
# summary(ANCOVA)

#model2<-lm(RelativeFitness ~ TRT + Block + PC1 + PC2 + PC3 + PC4 + richScaled + InvSimScaled + EvenScaled + TRT:Block + Block:PC1 + Block:PC2 + Block:PC3 + Block:PC4 + Block:richScaled + Block:InvSimScaled + Block:EvenScaled + TRT:PC1 + TRT:PC2 + TRT:PC3 + TRT:PC4 + TRT:Block:PC1 + TRT:Block:PC2 + TRT:Block:PC3 + TRT:Block:PC4,RootFitAlpha)


#interact_plot(ANCOVA,pred=PC1,modx=TRT,partial.residuals=TRUE)

# Multivariate phenotypic selection


# Within treatment
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+richScaled+InvSimScaled+EvenScaled,RootFitAlpha%>%filter(TRT=="Alone"))) # Alone
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + richScaled + 
##     InvSimScaled + EvenScaled, data = RootFitAlpha %>% filter(TRT == 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.64910 -0.35948  0.00188  0.10703  1.07359 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.17635    0.26534   4.433 0.000417 ***
## PC1           0.11957    0.10004   1.195 0.249447    
## PC2          -0.06590    0.10047  -0.656 0.521187    
## PC3          -0.09312    0.24367  -0.382 0.707371    
## PC4           0.28170    0.19059   1.478 0.158807    
## richScaled   -0.48344    1.00200  -0.482 0.636005    
## InvSimScaled  0.21564    0.51604   0.418 0.681594    
## EvenScaled   -0.46886    0.74682  -0.628 0.538991    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5084 on 16 degrees of freedom
## Multiple R-squared:  0.2441, Adjusted R-squared:  -0.08658 
## F-statistic: 0.7382 on 7 and 16 DF,  p-value: 0.6438
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+richScaled+InvSimScaled+EvenScaled,RootFitAlpha%>%filter(TRT!="Alone"))) # Competition
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + richScaled + 
##     InvSimScaled + EvenScaled, data = RootFitAlpha %>% filter(TRT != 
##     "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55765 -0.25407 -0.00441  0.20807  1.15789 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.03219    0.05063  20.386   <2e-16 ***
## PC1          -0.08358    0.07419  -1.127    0.264    
## PC2          -0.07021    0.10556  -0.665    0.508    
## PC3          -0.14197    0.15178  -0.935    0.353    
## PC4           0.09987    0.14862   0.672    0.504    
## richScaled   -0.27359    0.22559  -1.213    0.230    
## InvSimScaled  0.18017    0.11452   1.573    0.121    
## EvenScaled   -0.28159    0.16822  -1.674    0.099 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3542 on 65 degrees of freedom
## Multiple R-squared:  0.1396, Adjusted R-squared:  0.04692 
## F-statistic: 1.506 on 7 and 65 DF,  p-value: 0.1808
# report
summary(lm(RelativeFitness~rich,RootFitAlpha%>%filter(TRT=="Alone"))) # Alone
## 
## Call:
## lm(formula = RelativeFitness ~ rich, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5235 -0.3408 -0.1732  0.2074  1.1566 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.784092   1.427398  -0.549    0.588
## rich         0.003734   0.003132   1.192    0.246
## 
## Residual standard error: 0.4834 on 22 degrees of freedom
## Multiple R-squared:  0.06071,    Adjusted R-squared:  0.01801 
## F-statistic: 1.422 on 1 and 22 DF,  p-value: 0.2458
summary(lm(RelativeFitness~rich,RootFitAlpha%>%filter(TRT!="Alone"))) # Competition
## 
## Call:
## lm(formula = RelativeFitness ~ rich, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53579 -0.29469 -0.01234  0.22797  1.13305 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.255525   0.572115  -0.447   0.6565  
## rich         0.002806   0.001281   2.190   0.0318 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3536 on 71 degrees of freedom
## Multiple R-squared:  0.06326,    Adjusted R-squared:  0.05006 
## F-statistic: 4.794 on 1 and 71 DF,  p-value: 0.03184
# plot
ggplot(data=RootFitAlpha,aes(rich,RelativeFitness,color=TRT))+
geom_point(alpha=0.5,size=3) + 
geom_smooth(method=lm, se=FALSE, fullrange=TRUE,size=2)+
  theme_classic()+
  xlab("Richness")+
  Tx+
  theme(axis.text.x = element_text(angle=0,hjust = 0.5),axis.text=element_text(color="black",size=15))+ 
  scale_color_manual(values = c("#d8b365","#5ab4ac"),"Treatment", labels = c("Alone", "Competition"))+ 
  theme(legend.position = c(0.2, 0.9))
## `geom_smooth()` using formula 'y ~ x'

# Plot
EvenPlot1<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(TRT=="Alone"),aes(EvenScaled,RelativeFitness),size=3,alpha=0.5)+
#    geom_smooth(data=RootFitAlpha%>%filter(TRT=="Alone"),aes(even,RelativeFitness),method="lm",fullrange=TRUE,se=FALSE)+
  geom_abline(slope=-0.47,intercept = 1.18,color="blue",size=2)+
  theme_classic()+
  xlab("Evenness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))+
  scale_x_continuous(breaks = scales::pretty_breaks(n = 5))


EvenPlot2<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(TRT=="Inter"),aes(EvenScaled,RelativeFitness),size=3,alpha=0.5)+
#    geom_smooth(data=RootFitAlpha%>%filter(TRT=="Inter"),aes(EvenScaled,RelativeFitness),method="lm",fullrange=TRUE,se=FALSE)+
    geom_abline(slope=-0.28,intercept = 1.03,color="blue",size=2)+

  theme_classic()+
  xlab("Evenness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))+
  scale_x_continuous(breaks = scales::pretty_breaks(n = 5))

ggplot()+
  geom_point(data=RootFitAlpha,aes(EvenScaled,RelativeFitness,color=TRT),size=3,alpha=0.5)+
#    geom_smooth(data=RootFitAlpha%>%filter(TRT=="Inter"),aes(EvenScaled,RelativeFitness),method="lm",fullrange=TRUE,se=FALSE)+
    geom_abline(slope=-0.47,intercept = 1.18,color="red",size=2,linetype="dashed")+

    geom_abline(slope=-0.28,intercept = 1.03,color="black",size=2)+

  theme_classic()+
  xlab("Evenness")+
  Tx2+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))+
  scale_x_continuous(breaks = scales::pretty_breaks(n = 5)) + scale_color_manual(values = c("red","black"),"Treatment", labels = c("Alone", "Competition"))

#ggarrange(P2.rich,P2.even,P4.Sim,P4.simIn,nrow=2,ncol=2)
cowplot::plot_grid(EvenPlot1,EvenPlot2,align = "hv", ncol = 2,labels =c("A","B"), label_size =22 ,hjust=-9,vjust=2,label_x = -0.16)

Block1<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(Block=="1"),aes(even,RelativeFitness),size=3,alpha=0.5)+
    geom_smooth(data=RootFitAlpha%>%filter(Block=="1"),aes(even,RelativeFitness),se=FALSE,method="lm",fullrange=TRUE)+
    theme_classic()+
  xlab("Eveness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))
   
Block2<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(Block=="2"),aes(even,RelativeFitness),size=3,alpha=0.5)+
    geom_smooth(data=RootFitAlpha%>%filter(Block=="2"),aes(even,RelativeFitness),se=FALSE,method="lm",fullrange=TRUE)+
    theme_classic()+
  xlab("Eveness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))


Block3<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(Block=="3"),aes(even,RelativeFitness),size=3,alpha=0.5)+
    geom_smooth(data=RootFitAlpha%>%filter(Block=="3"),aes(even,RelativeFitness),se=FALSE,method="lm",fullrange=TRUE)+
    theme_classic()+
  xlab("Eveness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))


Block4<-ggplot()+
  geom_point(data=RootFitAlpha%>%filter(Block=="4"),aes(even,RelativeFitness),size=3,alpha=0.5)+
    geom_smooth(data=RootFitAlpha%>%filter(Block=="4"),aes(even,RelativeFitness),method="lm",fullrange=TRUE)+
    theme_classic()+
  xlab("Eveness")+
  Tx+
  theme(axis.text.x = element_text(angle=45),axis.text=element_text(color="black",size=15,vjust = 0.5,hjust=1))

# Modeling each diversity metric alone w ea root trait

summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+sim,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + sim, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.64505 -0.33239 -0.03507  0.16828  1.10462 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.65354   19.49486  -0.136    0.893
## PC1          0.11786    0.09723   1.212    0.241
## PC2         -0.06646    0.09724  -0.683    0.503
## PC3         -0.09046    0.21132  -0.428    0.674
## PC4          0.28639    0.17811   1.608    0.125
## sim          3.93219   20.00809   0.197    0.846
## 
## Residual standard error: 0.4962 on 18 degrees of freedom
## Multiple R-squared:   0.19,  Adjusted R-squared:  -0.03499 
## F-statistic: 0.8445 on 5 and 18 DF,  p-value: 0.5359
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+sim,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + sim, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43898 -0.30872 -0.03749  0.25095  1.17923 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.54213    5.05606  -0.898    0.372
## PC1         -0.10647    0.07433  -1.432    0.157
## PC2         -0.10829    0.10740  -1.008    0.317
## PC3         -0.13152    0.15697  -0.838    0.405
## PC4          0.10315    0.15161   0.680    0.499
## sim          5.73704    5.20506   1.102    0.274
## 
## Residual standard error: 0.3661 on 67 degrees of freedom
## Multiple R-squared:  0.05232,    Adjusted R-squared:  -0.01841 
## F-statistic: 0.7397 on 5 and 67 DF,  p-value: 0.5964
#anova(lm(RelativeFitness~PC1*TRT*sim+PC2*TRT*sim+PC3*TRT*sim+PC4*TRT*sim,RootFitAlpha))


summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+InvSimp,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + InvSimp, 
##     data = RootFitAlpha %>% filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.66299 -0.33841 -0.02993  0.17095  1.09615 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.898837   0.643575   1.397    0.180
## PC1          0.113985   0.096335   1.183    0.252
## PC2         -0.075642   0.096894  -0.781    0.445
## PC3         -0.099766   0.211519  -0.472    0.643
## PC4          0.286787   0.177067   1.620    0.123
## InvSimp      0.007066   0.015514   0.455    0.654
## 
## Residual standard error: 0.4939 on 18 degrees of freedom
## Multiple R-squared:  0.1975, Adjusted R-squared:  -0.02539 
## F-statistic: 0.8861 on 5 and 18 DF,  p-value: 0.5105
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+InvSimp,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + InvSimp, 
##     data = RootFitAlpha %>% filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.45015 -0.29744 -0.03431  0.24845  1.17892 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.770708   0.169949   4.535 2.45e-05 ***
## PC1         -0.108078   0.073328  -1.474    0.145    
## PC2         -0.098238   0.106567  -0.922    0.360    
## PC3         -0.142380   0.155322  -0.917    0.363    
## PC4          0.110665   0.149888   0.738    0.463    
## InvSimp      0.006901   0.004303   1.604    0.114    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3625 on 67 degrees of freedom
## Multiple R-squared:  0.0708, Adjusted R-squared:  0.001452 
## F-statistic: 1.021 on 5 and 67 DF,  p-value: 0.4125
#anova(lm(RelativeFitness~PC1*TRT*InvSimp+PC2*TRT*InvSimp+PC3*TRT*InvSimp+PC4*TRT*InvSimp,RootFitAlpha))

summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+even,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + even, 
##     data = RootFitAlpha %>% filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.69203 -0.38616  0.01376  0.14850  1.01700 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)    3.52036    2.30274   1.529    0.144
## PC1            0.11189    0.09324   1.200    0.246
## PC2           -0.06868    0.08866  -0.775    0.449
## PC3           -0.05379    0.20776  -0.259    0.799
## PC4            0.26152    0.17450   1.499    0.151
## even        -233.27167  228.46435  -1.021    0.321
## 
## Residual standard error: 0.483 on 18 degrees of freedom
## Multiple R-squared:  0.2327, Adjusted R-squared:  0.01957 
## F-statistic: 1.092 on 5 and 18 DF,  p-value: 0.3985
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+even,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + even, 
##     data = RootFitAlpha %>% filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.58133 -0.26839 -0.04516  0.20660  1.13952 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)    3.17372    0.97368   3.259  0.00176 **
## PC1           -0.09717    0.07170  -1.355  0.17990   
## PC2           -0.09793    0.10476  -0.935  0.35324   
## PC3           -0.11787    0.15115  -0.780  0.43825   
## PC4            0.07455    0.14849   0.502  0.61729   
## even        -206.75789   93.79970  -2.204  0.03095 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3567 on 67 degrees of freedom
## Multiple R-squared:  0.1004, Adjusted R-squared:  0.03324 
## F-statistic: 1.495 on 5 and 67 DF,  p-value: 0.2032
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+rich,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + rich, 
##     data = RootFitAlpha %>% filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.65902 -0.36686 -0.00494  0.17090  1.02814 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.202579   1.592825  -0.127    0.900
## PC1          0.108889   0.094578   1.151    0.265
## PC2         -0.076182   0.090884  -0.838    0.413
## PC3         -0.065021   0.208245  -0.312    0.758
## PC4          0.266736   0.175514   1.520    0.146
## rich         0.002936   0.003363   0.873    0.394
## 
## Residual standard error: 0.4866 on 18 degrees of freedom
## Multiple R-squared:  0.2213, Adjusted R-squared:  0.004934 
## F-statistic: 1.023 on 5 and 18 DF,  p-value: 0.4335
summary(lm(RelativeFitness~PC1+PC2+PC3+PC4+rich,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ PC1 + PC2 + PC3 + PC4 + rich, 
##     data = RootFitAlpha %>% filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55525 -0.28087 -0.03618  0.19842  1.11938 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.325487   0.609570  -0.534    0.595  
## PC1         -0.114317   0.072162  -1.584    0.118  
## PC2         -0.100462   0.104622  -0.960    0.340  
## PC3         -0.142405   0.151864  -0.938    0.352  
## PC4          0.074575   0.148336   0.503    0.617  
## rich         0.003047   0.001365   2.232    0.029 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3564 on 67 degrees of freedom
## Multiple R-squared:  0.1019, Adjusted R-squared:  0.03489 
## F-statistic: 1.521 on 5 and 67 DF,  p-value: 0.1952
# Interactions on fitness trait by alpha
EvenPC<-lm(RelativeFitness~TRT+Block+TRT:Block+TRT*PC1*EvenScaled+TRT*PC2*EvenScaled+TRT*PC3*EvenScaled+TRT*PC4*EvenScaled,RootFitAlpha)
anova(EvenPC)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                    Df Sum Sq Mean Sq F value    Pr(>F)    
## TRT                 1 0.1156 0.11565  1.5556   0.21641    
## Block               3 8.0999 2.69998 36.3172 2.447e-14 ***
## PC1                 1 0.0374 0.03735  0.5024   0.48075    
## EvenScaled          1 0.0047 0.00465  0.0626   0.80317    
## PC2                 1 0.0024 0.00242  0.0325   0.85743    
## PC3                 1 0.2499 0.24990  3.3614   0.07093 .  
## PC4                 1 0.0031 0.00305  0.0410   0.84004    
## TRT:Block           3 0.3390 0.11301  1.5201   0.21675    
## TRT:PC1             1 0.0033 0.00332  0.0447   0.83317    
## TRT:EvenScaled      1 0.1245 0.12451  1.6748   0.19981    
## PC1:EvenScaled      1 0.0311 0.03105  0.4177   0.52017    
## TRT:PC2             1 0.0016 0.00159  0.0214   0.88399    
## EvenScaled:PC2      1 0.0066 0.00661  0.0889   0.76642    
## TRT:PC3             1 0.0459 0.04588  0.6172   0.43472    
## EvenScaled:PC3      1 0.1735 0.17346  2.3332   0.13108    
## TRT:PC4             1 0.0008 0.00077  0.0104   0.91907    
## EvenScaled:PC4      1 0.1506 0.15057  2.0253   0.15908    
## TRT:PC1:EvenScaled  1 0.0279 0.02793  0.3757   0.54185    
## TRT:EvenScaled:PC2  1 0.0085 0.00847  0.1139   0.73678    
## TRT:EvenScaled:PC3  1 0.1939 0.19387  2.6077   0.11078    
## TRT:EvenScaled:PC4  1 0.1652 0.16520  2.2221   0.14048    
## Residuals          71 5.2784 0.07434                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
simPC<-lm(RelativeFitness~TRT+Block+TRT:Block+TRT*PC1*SimScaled+TRT*PC2*SimScaled+TRT*PC3*SimScaled+TRT*PC4*SimScaled,RootFitAlpha)
anova(simPC)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## TRT                1 0.1156 0.11565  1.5114  0.222982    
## Block              3 8.0999 2.69998 35.2858 4.504e-14 ***
## PC1                1 0.0374 0.03735  0.4882  0.487023    
## SimScaled          1 0.0132 0.01318  0.1722  0.679412    
## PC2                1 0.0021 0.00206  0.0269  0.870253    
## PC3                1 0.2375 0.23753  3.1043  0.082392 .  
## PC4                1 0.0022 0.00215  0.0281  0.867278    
## TRT:Block          3 0.3188 0.10627  1.3888  0.253273    
## TRT:PC1            1 0.0033 0.00331  0.0433  0.835723    
## TRT:SimScaled      1 0.0332 0.03316  0.4334  0.512440    
## PC1:SimScaled      1 0.0625 0.06248  0.8165  0.369266    
## TRT:PC2            1 0.0006 0.00056  0.0073  0.932273    
## SimScaled:PC2      1 0.0056 0.00564  0.0737  0.786853    
## TRT:PC3            1 0.0967 0.09669  1.2636  0.264755    
## SimScaled:PC3      1 0.0004 0.00039  0.0052  0.942968    
## TRT:PC4            1 0.0006 0.00056  0.0074  0.931808    
## SimScaled:PC4      1 0.0028 0.00278  0.0363  0.849475    
## TRT:PC1:SimScaled  1 0.0000 0.00000  0.0000  0.994913    
## TRT:SimScaled:PC2  1 0.0326 0.03261  0.4262  0.515983    
## TRT:SimScaled:PC3  1 0.5603 0.56034  7.3230  0.008519 ** 
## TRT:SimScaled:PC4  1 0.0058 0.00577  0.0754  0.784453    
## Residuals         71 5.4327 0.07652                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
richPC<-lm(RelativeFitness~TRT+Block+TRT:Block+TRT*PC1*richScaled+TRT*PC2*richScaled+TRT*PC3*richScaled+TRT*PC4*richScaled,RootFitAlpha)
anova(richPC)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                    Df Sum Sq Mean Sq F value    Pr(>F)    
## TRT                 1 0.1156 0.11565  1.6671  0.200840    
## Block               3 8.0999 2.69998 38.9198 5.487e-15 ***
## PC1                 1 0.0374 0.03735  0.5385  0.465490    
## richScaled          1 0.0002 0.00018  0.0025  0.959872    
## PC2                 1 0.0022 0.00219  0.0315  0.859539    
## PC3                 1 0.2512 0.25119  3.6209  0.061114 .  
## PC4                 1 0.0028 0.00280  0.0404  0.841275    
## TRT:Block           3 0.3265 0.10883  1.5687  0.204526    
## TRT:PC1             1 0.0030 0.00297  0.0428  0.836618    
## TRT:richScaled      1 0.1475 0.14750  2.1262  0.149209    
## PC1:richScaled      1 0.0126 0.01256  0.1811  0.671744    
## TRT:PC2             1 0.0041 0.00413  0.0596  0.807853    
## richScaled:PC2      1 0.0000 0.00001  0.0001  0.992092    
## TRT:PC3             1 0.0604 0.06045  0.8714  0.353741    
## richScaled:PC3      1 0.1173 0.11733  1.6913  0.197638    
## TRT:PC4             1 0.0036 0.00362  0.0522  0.819934    
## richScaled:PC4      1 0.2167 0.21667  3.1233  0.081478 .  
## TRT:PC1:richScaled  1 0.0987 0.09873  1.4232  0.236842    
## TRT:richScaled:PC2  1 0.0047 0.00472  0.0681  0.794896    
## TRT:richScaled:PC3  1 0.5596 0.55959  8.0663  0.005879 ** 
## TRT:richScaled:PC4  1 0.0741 0.07413  1.0686  0.304778    
## Residuals          71 4.9255 0.06937                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
InSimPC<-lm(RelativeFitness~TRT+Block+TRT:Block+TRT*PC1*InvSimScaled+TRT*PC2*InvSimScaled+TRT*PC3*InvSimScaled+TRT*PC4*InvSimScaled,RootFitAlpha)
anova(InSimPC)
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                      Df Sum Sq Mean Sq F value    Pr(>F)    
## TRT                   1 0.1156 0.11565  1.5247  0.220983    
## Block                 3 8.0999 2.69998 35.5956 3.746e-14 ***
## PC1                   1 0.0374 0.03735  0.4925  0.485124    
## InvSimScaled          1 0.0093 0.00930  0.1226  0.727252    
## PC2                   1 0.0023 0.00229  0.0302  0.862469    
## PC3                   1 0.2411 0.24110  3.1786  0.078884 .  
## PC4                   1 0.0023 0.00233  0.0307  0.861351    
## TRT:Block             3 0.3180 0.10600  1.3974  0.250711    
## TRT:PC1               1 0.0033 0.00329  0.0434  0.835652    
## TRT:InvSimScaled      1 0.0466 0.04661  0.6145  0.435718    
## PC1:InvSimScaled      1 0.0223 0.02233  0.2944  0.589144    
## TRT:PC2               1 0.0002 0.00019  0.0025  0.960458    
## InvSimScaled:PC2      1 0.0125 0.01245  0.1642  0.686582    
## TRT:PC3               1 0.1008 0.10084  1.3295  0.252763    
## InvSimScaled:PC3      1 0.0212 0.02123  0.2799  0.598445    
## TRT:PC4               1 0.0022 0.00217  0.0286  0.866191    
## InvSimScaled:PC4      1 0.0002 0.00018  0.0023  0.961627    
## TRT:PC1:InvSimScaled  1 0.0036 0.00359  0.0473  0.828451    
## TRT:InvSimScaled:PC2  1 0.0104 0.01041  0.1372  0.712137    
## TRT:InvSimScaled:PC3  1 0.6097 0.60968  8.0379  0.005963 ** 
## TRT:InvSimScaled:PC4  1 0.0193 0.01931  0.2546  0.615389    
## Residuals            71 5.3855 0.07585                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(RelativeFitness~Block+PC1*InvSimScaled+PC2*InvSimScaled+PC3*InvSimScaled+PC4*InvSimScaled,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * InvSimScaled + PC2 * 
##     InvSimScaled + PC3 * InvSimScaled + PC4 * InvSimScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73064 -0.13685 -0.01639  0.07604  0.94018 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)  
## (Intercept)       0.492978   0.400872   1.230   0.2444  
## Block2           -0.007347   0.344926  -0.021   0.9834  
## Block3            0.863237   0.439762   1.963   0.0754 .
## Block4            0.697341   0.372942   1.870   0.0883 .
## PC1              -0.123130   0.138362  -0.890   0.3926  
## InvSimScaled     -0.337368   0.437350  -0.771   0.4567  
## PC2              -0.036539   0.138113  -0.265   0.7962  
## PC3              -0.336042   0.248689  -1.351   0.2038  
## PC4              -0.154334   0.307107  -0.503   0.6252  
## PC1:InvSimScaled  0.110013   0.195818   0.562   0.5855  
## InvSimScaled:PC2  0.064561   0.195868   0.330   0.7479  
## InvSimScaled:PC3  0.746208   0.582340   1.281   0.2264  
## InvSimScaled:PC4 -0.077289   0.429471  -0.180   0.8605  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4986 on 11 degrees of freedom
## Multiple R-squared:  0.5003, Adjusted R-squared:  -0.04489 
## F-statistic: 0.9177 on 12 and 11 DF,  p-value: 0.5601
summary(lm(RelativeFitness~Block+PC1*InvSimScaled+PC2*InvSimScaled+PC3*InvSimScaled+PC4*InvSimScaled,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * InvSimScaled + PC2 * 
##     InvSimScaled + PC3 * InvSimScaled + PC4 * InvSimScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.36529 -0.11695 -0.00889  0.06757  0.65663 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       0.6755687  0.0601181  11.237  < 2e-16 ***
## Block2            0.0968576  0.0739515   1.310    0.195    
## Block3            0.7870096  0.0768932  10.235 8.80e-15 ***
## Block4            0.3397215  0.0757624   4.484 3.36e-05 ***
## PC1               0.0111949  0.0453835   0.247    0.806    
## InvSimScaled     -0.0009261  0.0325830  -0.028    0.977    
## PC2              -0.0131862  0.0641224  -0.206    0.838    
## PC3              -0.0545295  0.0979270  -0.557    0.580    
## PC4              -0.0273720  0.0932287  -0.294    0.770    
## PC1:InvSimScaled -0.0510828  0.0400841  -1.274    0.207    
## InvSimScaled:PC2 -0.0590744  0.0668230  -0.884    0.380    
## InvSimScaled:PC3 -0.0590930  0.0899463  -0.657    0.514    
## InvSimScaled:PC4  0.0578580  0.0948641   0.610    0.544    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2102 on 60 degrees of freedom
## Multiple R-squared:  0.7203, Adjusted R-squared:  0.6643 
## F-statistic: 12.87 on 12 and 60 DF,  p-value: 1.696e-12
summary(lm(RelativeFitness~Block+PC1*richScaled+PC2*richScaled+PC3*richScaled+PC4*richScaled,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * richScaled + PC2 * 
##     richScaled + PC3 * richScaled + PC4 * richScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.88722 -0.12583  0.00799  0.06562  0.69200 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)     0.610901   0.403832   1.513   0.1585  
## Block2          0.076867   0.338040   0.227   0.8243  
## Block3          0.631606   0.406460   1.554   0.1485  
## Block4          0.885831   0.362321   2.445   0.0325 *
## PC1            -0.165221   0.128337  -1.287   0.2244  
## richScaled      0.071313   0.235943   0.302   0.7681  
## PC2            -0.008097   0.122535  -0.066   0.9485  
## PC3            -0.612154   0.325889  -1.878   0.0871 .
## PC4            -0.244002   0.303774  -0.803   0.4389  
## PC1:richScaled  0.213433   0.124198   1.718   0.1137  
## richScaled:PC2 -0.048626   0.193401  -0.251   0.8061  
## richScaled:PC3  0.544370   0.304099   1.790   0.1010  
## richScaled:PC4  0.212981   0.361252   0.590   0.5674  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4524 on 11 degrees of freedom
## Multiple R-squared:  0.5886, Adjusted R-squared:  0.1398 
## F-statistic: 1.311 on 12 and 11 DF,  p-value: 0.3303
summary(lm(RelativeFitness~Block+PC1*richScaled+PC2*richScaled+PC3*richScaled+PC4*richScaled,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * richScaled + PC2 * 
##     richScaled + PC3 * richScaled + PC4 * richScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.37866 -0.10560 -0.00834  0.07669  0.61287 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.692264   0.060744  11.396  < 2e-16 ***
## Block2          0.081721   0.074871   1.091    0.279    
## Block3          0.778519   0.077741  10.014 2.02e-14 ***
## Block4          0.339075   0.076532   4.431 4.06e-05 ***
## PC1            -0.002917   0.048868  -0.060    0.953    
## richScaled     -0.009322   0.036981  -0.252    0.802    
## PC2            -0.014292   0.064311  -0.222    0.825    
## PC3            -0.088420   0.096568  -0.916    0.364    
## PC4            -0.040077   0.091576  -0.438    0.663    
## PC1:richScaled -0.037381   0.045352  -0.824    0.413    
## richScaled:PC2 -0.047871   0.067843  -0.706    0.483    
## richScaled:PC3 -0.077137   0.089918  -0.858    0.394    
## richScaled:PC4 -0.042623   0.104220  -0.409    0.684    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2111 on 60 degrees of freedom
## Multiple R-squared:  0.7178, Adjusted R-squared:  0.6614 
## F-statistic: 12.72 on 12 and 60 DF,  p-value: 2.169e-12
summary(lm(RelativeFitness~Block+PC1*richScaled+PC2*richScaled+PC3*richScaled+PC4*richScaled,RootFitAlpha%>%filter(TRT=="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * richScaled + PC2 * 
##     richScaled + PC3 * richScaled + PC4 * richScaled, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.88722 -0.12583  0.00799  0.06562  0.69200 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)     0.610901   0.403832   1.513   0.1585  
## Block2          0.076867   0.338040   0.227   0.8243  
## Block3          0.631606   0.406460   1.554   0.1485  
## Block4          0.885831   0.362321   2.445   0.0325 *
## PC1            -0.165221   0.128337  -1.287   0.2244  
## richScaled      0.071313   0.235943   0.302   0.7681  
## PC2            -0.008097   0.122535  -0.066   0.9485  
## PC3            -0.612154   0.325889  -1.878   0.0871 .
## PC4            -0.244002   0.303774  -0.803   0.4389  
## PC1:richScaled  0.213433   0.124198   1.718   0.1137  
## richScaled:PC2 -0.048626   0.193401  -0.251   0.8061  
## richScaled:PC3  0.544370   0.304099   1.790   0.1010  
## richScaled:PC4  0.212981   0.361252   0.590   0.5674  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4524 on 11 degrees of freedom
## Multiple R-squared:  0.5886, Adjusted R-squared:  0.1398 
## F-statistic: 1.311 on 12 and 11 DF,  p-value: 0.3303
summary(lm(RelativeFitness~Block+PC1*richScaled+PC2*richScaled+PC3*richScaled+PC4*richScaled,RootFitAlpha%>%filter(TRT!="Alone")))
## 
## Call:
## lm(formula = RelativeFitness ~ Block + PC1 * richScaled + PC2 * 
##     richScaled + PC3 * richScaled + PC4 * richScaled, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.37866 -0.10560 -0.00834  0.07669  0.61287 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.692264   0.060744  11.396  < 2e-16 ***
## Block2          0.081721   0.074871   1.091    0.279    
## Block3          0.778519   0.077741  10.014 2.02e-14 ***
## Block4          0.339075   0.076532   4.431 4.06e-05 ***
## PC1            -0.002917   0.048868  -0.060    0.953    
## richScaled     -0.009322   0.036981  -0.252    0.802    
## PC2            -0.014292   0.064311  -0.222    0.825    
## PC3            -0.088420   0.096568  -0.916    0.364    
## PC4            -0.040077   0.091576  -0.438    0.663    
## PC1:richScaled -0.037381   0.045352  -0.824    0.413    
## richScaled:PC2 -0.047871   0.067843  -0.706    0.483    
## richScaled:PC3 -0.077137   0.089918  -0.858    0.394    
## richScaled:PC4 -0.042623   0.104220  -0.409    0.684    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2111 on 60 degrees of freedom
## Multiple R-squared:  0.7178, Adjusted R-squared:  0.6614 
## F-statistic: 12.72 on 12 and 60 DF,  p-value: 2.169e-12

Plotting 3D Plane

library(scatterplot3d) # This library will allow us to draw 3d plot
library("plot3D")

#Subset by treatment
RootFitAlphaAlone=RootFitAlpha%>%filter(TRT=="Alone")
RootFitAlphaComp=RootFitAlpha%>%filter(TRT!="Alone")

# Input data
x <- RootFitAlphaAlone$PC3
y <- RootFitAlphaAlone$sim
z <- RootFitAlphaAlone$RelativeFitness


# Compute the linear regression (z = ax + by + d)
fit <- lm(z ~ x + y)
# predict values on regular xy grid
grid.lines = 26
x.pred <- seq(min(x), max(x), length.out = grid.lines)
y.pred <- seq(min(y), max(y), length.out = grid.lines)
xy <- expand.grid( x = x.pred, y = y.pred)
z.pred <- matrix(predict(fit, newdata = xy), 
                 nrow = grid.lines, ncol = grid.lines)
# fitted points for droplines to surface
fitpoints <- predict(fit)

# Root trait × Treatment × Simpson diversity

# scatter plot with regression plane
scatter3D(x, y, z, pch = 18, cex = 2, 
    theta =135, phi = 10, colvar = NULL, col = "blue",
    xlab = "Root Size", ylab = "Simpson Diversity", zlab = "Relative Fitness",  
    surf = list(x = x.pred, y = y.pred, z = z.pred,  
    facets = NA, fit = fitpoints), main = "Absence of Competition")

# Repeat for competition treatment
# Input data
x <- RootFitAlphaComp$PC3
y <- RootFitAlphaComp$sim
z <- RootFitAlphaComp$RelativeFitness


# Compute the linear regression (z = ax + by + d)
fit <- lm(z ~ x + y)
# predict values on regular xy grid
grid.lines = 26
x.pred <- seq(min(x), max(x), length.out = grid.lines)
y.pred <- seq(min(y), max(y), length.out = grid.lines)
xy <- expand.grid( x = x.pred, y = y.pred)
z.pred <- matrix(predict(fit, newdata = xy), 
                 nrow = grid.lines, ncol = grid.lines)
# fitted points for droplines to surface
fitpoints <- predict(fit)
# scatter plot with regression plane

s3d <- scatterplot3d(x,y,z,  highlight.3d=FALSE, scale.y=.5, pch=16, main = "Presence of Competition",
    xlab = "Root Size", ylab = "Simpson Diversity", zlab = "Relative Fitness", color="steelblue",angle=30) # Now adding some points to the "scatterplot3d"


s3d$points3d(seq(10,20,2), seq(85,60,-5), seq(60,10,-10),col="steelblue", type="h", pch=16,scale=2)# Now adding a regression plane to the "scatterplot3d"attach(trees)
## Warning in segments(x, y, x, y2, ...): "scale" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "scale" is not a
## graphical parameter
my.lm <- lm(z ~ x + y)
s3d$plane3d(my.lm, lty.box = "solid")

scatter3D(x, y, z, pch = 18, cex = 2, 
    theta =45, phi = 10, colvar = NULL, col = "blue",
    xlab = "Root Size", ylab = "Simpson Diversity", zlab = "Relative Fitness",  
    surf = list(x = x.pred, y = y.pred, z = z.pred,  
    facets = NA, fit = fitpoints), main = "Presence of Competition")

points3D(x, y, z, pch = 16, col="black", alpha = 0.8, add=TRUE)

# Root trait × Treatment × Inverse Simpson diversity

  # Competition treatment
  y <- RootFitAlphaComp$InvSimp
  
  # Compute the linear regression (z = ax + by + d)
  fit <- lm(z ~ x + y)
  # predict values on regular xy grid
  grid.lines = 26
  x.pred <- seq(min(x), max(x), length.out = grid.lines)
  y.pred <- seq(min(y), max(y), length.out = grid.lines)
  xy <- expand.grid( x = x.pred, y = y.pred)
  z.pred <- matrix(predict(fit, newdata = xy), 
                   nrow = grid.lines, ncol = grid.lines)
  
  scatter3D(x, y, z, pch = 18, cex = 2, 
      theta =45, phi = 10, colvar = NULL, col = "blue",
      xlab = "Root Size", ylab = "Inverse Simpson Diversity", zlab = "Relative Fitness",  
      surf = list(x = x.pred, y = y.pred, z = z.pred,  
      facets = NA, fit = fitpoints), main = "Presence of Competition")
  
  points3D(x, y, z, pch = 16, col="black", alpha = 0.8, add=TRUE)

  # Absence of competition treatment
  y <- RootFitAlphaAlone$InvSimp
  x<-RootFitAlphaAlone$PC3
  z<-RootFitAlphaAlone$RelativeFitness
  # Compute the linear regression (z = ax + by + d)
  fit <- lm(z ~ x + y)
  # fitted points for droplines to surface
  fitpoints <- predict(fit)
  # predict values on regular xy grid
  grid.lines = 26
  x.pred <- seq(min(x), max(x), length.out = grid.lines)
  y.pred <- seq(min(y), max(y), length.out = grid.lines)
  xy <- expand.grid( x = x.pred, y = y.pred)
  z.pred <- matrix(predict(fit, newdata = xy), 
                   nrow = grid.lines, ncol = grid.lines)
  
  scatter3D(x, y, z, pch = 18, cex = 2, 
      theta =45, phi = 10, colvar = NULL, col = "blue",
      xlab = "Root Size", ylab = "Inverse Simpson Diversity", zlab = "Relative Fitness",  
      surf = list(x = x.pred, y = y.pred, z = z.pred,  
      facets = NA, fit = fitpoints), main = "Absence of Competition")

# Root trait × Treatment × Richness
  
    # Competition treatment
  y <- RootFitAlphaComp$rich
  x<-RootFitAlphaComp$PC3
  z<-RootFitAlphaComp$RelativeFitness  
  # Compute the linear regression (z = ax + by + d)
  fit <- lm(z ~ x + y)
  fitpoints <- predict(fit)

  # predict values on regular xy grid
  grid.lines = 26
  x.pred <- seq(min(x), max(x), length.out = grid.lines)
  y.pred <- seq(min(y), max(y), length.out = grid.lines)
  xy <- expand.grid( x = x.pred, y = y.pred)
  z.pred <- matrix(predict(fit, newdata = xy), 
                   nrow = grid.lines, ncol = grid.lines)
  
  scatter3D(x, y, z, pch = 18, cex = 2, 
      theta =45, phi = 10, colvar = NULL, col = "blue",
      xlab = "Root Size", ylab = "Richness", zlab = "Relative Fitness",  
      surf = list(x = x.pred, y = y.pred, z = z.pred,  
      facets = NA, fit = fitpoints), main = "Presence of Competition")

  # Absence of competition treatment
  y <- RootFitAlphaAlone$rich
  x<-RootFitAlphaAlone$PC3
  z<-RootFitAlphaAlone$RelativeFitness
  # Compute the linear regression (z = ax + by + d)
  fit <- lm(z ~ x + y)
  # fitted points for droplines to surface
  fitpoints <- predict(fit)
  # predict values on regular xy grid
  grid.lines = 26
  x.pred <- seq(min(x), max(x), length.out = grid.lines)
  y.pred <- seq(min(y), max(y), length.out = grid.lines)
  xy <- expand.grid( x = x.pred, y = y.pred)
  z.pred <- matrix(predict(fit, newdata = xy), 
                   nrow = grid.lines, ncol = grid.lines)
  
  scatter3D(x, y, z, pch = 18, cex = 2, 
      theta =45, phi = 10, colvar = NULL, col = "blue",
      xlab = "Root Size", ylab = "Richness", zlab = "Relative Fitness",  
      surf = list(x = x.pred, y = y.pred, z = z.pred,  
      facets = NA, fit = fitpoints), main = "Absence of Competition")

Quadratic relationships w fitness

RootFitAlpha$rich2<-RootFitAlpha$rich*RootFitAlpha$rich
RootFitAlpha$sim2<-RootFitAlpha$sim*RootFitAlpha$sim
RootFitAlpha$InvSimp2<-RootFitAlpha$InvSimp*RootFitAlpha$InvSimp
RootFitAlpha$even2<-RootFitAlpha$even*RootFitAlpha$even

AncovRich<-lm(RelativeFitness~rich2+rich+rich2*Block*Trt,RootFitAlpha)
AncovSim<-lm(RelativeFitness~sim2+sim+sim2*Block*Trt,RootFitAlpha)
AncovInSim<-lm(RelativeFitness~InvSimp2+InvSimp+InvSimp2*Block*Trt,RootFitAlpha)
AncovEven<-lm(RelativeFitness~even2+even+even2*Block*Trt,RootFitAlpha)

anova(AncovRich) # Significant quadratic richness term
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                 Df Sum Sq Mean Sq F value    Pr(>F)    
## rich2            1 0.8339 0.83392 10.8189  0.001495 ** 
## rich             1 0.0112 0.01123  0.1457  0.703738    
## Block            3 7.3905 2.46349 31.9602 1.109e-13 ***
## Trt              1 0.0445 0.04450  0.5773  0.449603    
## rich2:Block      3 0.1592 0.05307  0.6885  0.561677    
## rich2:Trt        1 0.0050 0.00496  0.0644  0.800335    
## Block:Trt        3 0.4176 0.13920  1.8059  0.152765    
## rich2:Block:Trt  3 0.0354 0.01180  0.1531  0.927421    
## Residuals       80 6.1664 0.07708                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovSim) #  NS
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                Df Sum Sq Mean Sq F value   Pr(>F)    
## sim2            1 0.1365 0.13653  1.7802   0.1859    
## sim             1 0.1116 0.11159  1.4550   0.2313    
## Block           3 7.9356 2.64520 34.4904 2.08e-14 ***
## Trt             1 0.0555 0.05551  0.7238   0.3974    
## sim2:Block      3 0.0577 0.01925  0.2510   0.8604    
## sim2:Trt        1 0.0001 0.00012  0.0016   0.9682    
## Block:Trt       3 0.3760 0.12533  1.6341   0.1880    
## sim2:Block:Trt  3 0.2551 0.08504  1.1088   0.3505    
## Residuals      80 6.1355 0.07669                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovInSim) # Significant quadratic Inverse Simpson term
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                    Df Sum Sq Mean Sq F value    Pr(>F)    
## InvSimp2            1 0.5022 0.50221  6.4441   0.01307 *  
## InvSimp             1 0.3673 0.36727  4.7127   0.03291 *  
## Block               3 7.3351 2.44502 31.3733 1.652e-13 ***
## Trt                 1 0.0390 0.03902  0.5007   0.48127    
## InvSimp2:Block      3 0.0231 0.00769  0.0987   0.96050    
## InvSimp2:Trt        1 0.0003 0.00028  0.0036   0.95217    
## Block:Trt           3 0.3859 0.12863  1.6505   0.18435    
## InvSimp2:Block:Trt  3 0.1762 0.05873  0.7537   0.52344    
## Residuals          80 6.2347 0.07793                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovEven) # Significant quadratic Even term
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                 Df Sum Sq Mean Sq F value    Pr(>F)    
## even2            1 0.9754 0.97536 13.2264 0.0004869 ***
## even             1 0.0227 0.02273  0.3083 0.5802959    
## Block            3 7.3830 2.46100 33.3724 4.321e-14 ***
## Trt              1 0.0418 0.04178  0.5666 0.4538191    
## even2:Block      3 0.1926 0.06420  0.8706 0.4599352    
## even2:Trt        1 0.0180 0.01796  0.2435 0.6230372    
## Block:Trt        3 0.4254 0.14179  1.9227 0.1325461    
## even2:Block:Trt  3 0.1054 0.03513  0.4764 0.6996033    
## Residuals       80 5.8995 0.07374                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Quadratic w Root Size

# Include root size and interactions as covariates 
AncovRich<-lm(RelativeFitness~rich2+rich+rich2*Block*Trt*PC3-rich2:Block:TRT:PC3,RootFitAlpha)

AncovSim<-lm(RelativeFitness~sim2+sim+sim2*Block*Trt*PC3-sim2:Block:TRT:PC3,RootFitAlpha)

AncovInSim<-lm(RelativeFitness~InvSimp2+InvSimp+InvSimp2*Block*Trt*PC3-InvSimp2:Block:TRT:PC3,RootFitAlpha)
AncovEven<-lm(RelativeFitness~even2+even+even2*Block*Trt*PC3-even2:Block:TRT:PC3,RootFitAlpha)

anova(AncovRich) # Significant quadratic richness term, NS treatment interaction
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                     Df Sum Sq Mean Sq F value    Pr(>F)    
## rich2                1 0.8339 0.83392 13.3655 0.0005193 ***
## rich                 1 0.0112 0.01123  0.1799 0.6728502    
## Block                3 7.3905 2.46349 39.4833 1.449e-14 ***
## Trt                  1 0.0445 0.04450  0.7132 0.4015301    
## PC3                  1 0.2519 0.25187  4.0368 0.0487390 *  
## rich2:Block          3 0.1126 0.03754  0.6016 0.6163056    
## rich2:Trt            1 0.0003 0.00032  0.0051 0.9430860    
## Block:Trt            3 0.3684 0.12280  1.9681 0.1276376    
## rich2:PC3            1 0.0264 0.02635  0.4224 0.5180901    
## Block:PC3            3 0.4803 0.16009  2.5659 0.0622405 .  
## Trt:PC3              1 0.2189 0.21890  3.5084 0.0656256 .  
## rich2:Block:Trt      3 0.0343 0.01142  0.1830 0.9075514    
## rich2:Block:PC3      3 0.7860 0.26201  4.1994 0.0089364 ** 
## rich2:Trt:PC3        1 0.0565 0.05646  0.9049 0.3450557    
## Block:Trt:PC3        3 0.3819 0.12730  2.0403 0.1170493    
## rich2:Block:Trt:PC3  3 0.0730 0.02433  0.3900 0.7605724    
## Residuals           64 3.9932 0.06239                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovSim) #  Significant quadratic Inverse Simpson term, significant trt by root by microbe **
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                    Df Sum Sq Mean Sq F value    Pr(>F)    
## sim2                1 0.1365 0.13653  2.0807   0.15405    
## sim                 1 0.1116 0.11159  1.7006   0.19689    
## Block               3 7.9356 2.64520 40.3114 9.429e-15 ***
## Trt                 1 0.0555 0.05551  0.8459   0.36116    
## PC3                 1 0.2032 0.20321  3.0969   0.08322 .  
## sim2:Block          3 0.0342 0.01139  0.1736   0.91385    
## sim2:Trt            1 0.0010 0.00095  0.0145   0.90456    
## Block:Trt           3 0.3653 0.12176  1.8556   0.14606    
## sim2:PC3            1 0.0171 0.01708  0.2603   0.61164    
## Block:PC3           3 0.4708 0.15693  2.3916   0.07675 .  
## Trt:PC3             1 0.1537 0.15368  2.3420   0.13086    
## sim2:Block:Trt      3 0.2445 0.08150  1.2420   0.30186    
## sim2:Block:PC3      3 0.0260 0.00868  0.1322   0.94054    
## sim2:Trt:PC3        1 0.3747 0.37465  5.7095   0.01983 *  
## Block:Trt:PC3       3 0.6030 0.20102  3.0634   0.03427 *  
## sim2:Block:Trt:PC3  3 0.1314 0.04380  0.6676   0.57506    
## Residuals          64 4.1996 0.06562                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovInSim) # Significant quadratic Inverse Simpson term, significant trt by root by microbe **
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                        Df Sum Sq Mean Sq F value    Pr(>F)    
## InvSimp2                1 0.5022 0.50221  7.4716  0.008095 ** 
## InvSimp                 1 0.3673 0.36727  5.4641  0.022551 *  
## Block                   3 7.3351 2.44502 36.3756 7.652e-14 ***
## Trt                     1 0.0390 0.03902  0.5805  0.448923    
## PC3                     1 0.2320 0.23202  3.4518  0.067783 .  
## InvSimp2:Block          3 0.0105 0.00349  0.0520  0.984223    
## InvSimp2:Trt            1 0.0001 0.00008  0.0012  0.972053    
## Block:Trt               3 0.3621 0.12071  1.7958  0.156878    
## InvSimp2:PC3            1 0.0259 0.02593  0.3858  0.536715    
## Block:PC3               3 0.4879 0.16264  2.4197  0.074199 .  
## Trt:PC3                 1 0.1329 0.13292  1.9776  0.164483    
## InvSimp2:Block:Trt      3 0.1780 0.05933  0.8826  0.454934    
## InvSimp2:Block:PC3      3 0.0087 0.00291  0.0434  0.987881    
## InvSimp2:Trt:PC3        1 0.3694 0.36945  5.4964  0.022171 *  
## Block:Trt:PC3           3 0.5965 0.19884  2.9582  0.038870 *  
## InvSimp2:Block:Trt:PC3  3 0.1141 0.03805  0.5661  0.639378    
## Residuals              64 4.3018 0.06722                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(AncovEven) # Significant quadratic Even term, NS treatment
## Analysis of Variance Table
## 
## Response: RelativeFitness
##                     Df Sum Sq Mean Sq F value    Pr(>F)    
## even2                1 0.9754 0.97536 16.2336 0.0001512 ***
## even                 1 0.0227 0.02273  0.3784 0.5406669    
## Block                3 7.3830 2.46100 40.9601 6.763e-15 ***
## Trt                  1 0.0418 0.04178  0.6954 0.4074239    
## PC3                  1 0.3382 0.33817  5.6284 0.0206883 *  
## even2:Block          3 0.1914 0.06380  1.0618 0.3716135    
## even2:Trt            1 0.0061 0.00614  0.1022 0.7502042    
## Block:Trt            3 0.3612 0.12042  2.0041 0.1222425    
## even2:PC3            1 0.0144 0.01444  0.2403 0.6256392    
## Block:PC3            3 0.3936 0.13119  2.1834 0.0985645 .  
## Trt:PC3              1 0.1842 0.18418  3.0654 0.0847648 .  
## even2:Block:Trt      3 0.0191 0.00637  0.1060 0.9562937    
## even2:Block:PC3      3 0.6193 0.20642  3.4357 0.0219896 *  
## even2:Trt:PC3        1 0.0703 0.07028  1.1697 0.2835151    
## Block:Trt:PC3        3 0.5243 0.17477  2.9087 0.0412432 *  
## even2:Block:Trt:PC3  3 0.0734 0.02447  0.4072 0.7483085    
## Residuals           64 3.8453 0.06008                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Within treatment for inverse simpson and simpson diversity
Sim_Size_Alone<-lm(RelativeFitness~InvSimp2+PC3,RootFitAlpha %>% filter(TRT=="Alone"))
summary(Sim_Size_Alone)
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimp2 + PC3, data = RootFitAlpha %>% 
##     filter(TRT == "Alone"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4977 -0.3350 -0.2025  0.2437  1.3048 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  8.793e-01  3.207e-01   2.742   0.0122 *
## InvSimp2     9.942e-05  1.895e-04   0.525   0.6053  
## PC3         -1.756e-01  2.005e-01  -0.875   0.3912  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4989 on 21 degrees of freedom
## Multiple R-squared:  0.04498,    Adjusted R-squared:  -0.04598 
## F-statistic: 0.4945 on 2 and 21 DF,  p-value: 0.6168
Sim_Size_Comp<-lm(RelativeFitness~InvSimp2+PC3,RootFitAlpha %>% filter(TRT!="Alone"))
summary(Sim_Size_Comp)
## 
## Call:
## lm(formula = RelativeFitness ~ InvSimp2 + PC3, data = RootFitAlpha %>% 
##     filter(TRT != "Alone"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.50941 -0.32491  0.00258  0.23801  1.14760 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.492e-01  8.914e-02   9.527 2.88e-14 ***
## InvSimp2     9.495e-05  5.112e-05   1.857   0.0675 .  
## PC3         -4.783e-02  1.195e-01  -0.400   0.6901    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3592 on 70 degrees of freedom
## Multiple R-squared:  0.04701,    Adjusted R-squared:  0.01979 
## F-statistic: 1.727 on 2 and 70 DF,  p-value: 0.1854

MANTEL test to examine how microbiome disimilarity is correlated root phenotype distance

MANTEL between Bray Curtis and Relative Fitnesses

#  Here we use the Family mean values of root traits---this would indicate evidence for 'phenotypic selection' 

  # Load matrix Bray distances of OTU abundance
  OTU_table=t(otu_table(physeq1)) # Write out OTU table
  

  # Pull out Root traits of interest and save these to the Sampled data frame
  SampledFit=merge(FitAveraged,sampledf,by=c("TRT","ML","Block"))

  # Subset per treatment
  
SampledFitComp=SampledFit%>%filter(TRT=="Inter")
OTU_table_Comp=OTU_table[row.names(OTU_table)%in%SampledFitComp$Sample_ID,]

SampledFitAlone=SampledFit%>%filter(TRT!="Inter")
OTU_table_Alone=OTU_table[row.names(OTU_table)%in%SampledFitAlone$Sample_ID,]

    OTU_Comp=OTU_table_Comp
    Fit_Comp=SampledFitComp
  
    OTU_Alone=OTU_table_Alone
    Fit_Alone=SampledFitAlone
    # Calculate fitness distances w euclidean distance 

    Fit.distComp=dist(Fit_Comp$RelativeFitness)
    Fit.distAlone=dist(Fit_Alone$RelativeFitness)

    # Calculate Bray distance matrix for OTU table
    BrayComp=vegdist(OTU_Comp,method="bray")
    BrayAlone=vegdist(OTU_Alone,method="bray")

    # OTU Bray vs Fitness per treatment

    OTU_Fit_Comp = mantel(BrayComp, Fit.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    OTU_Fit_Alone = mantel(BrayAlone, Fit.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    
# Run partial mantel test and control for plant size--i.e., plant size distance matrix
    
    # First  average combined fitness and leaf data 
    Fit2Average=FitnessPurp2%>%
      filter(Species=="Ip")%>%
      group_by(ML,Block,Trt)%>%
      summarise("RelativeFitAv"=mean(RelativeFit,rm.na=T),"LeafAv"=mean(Leaf.Number,rm.na=T))
    Fit2Average$TRT=Fit2Average$Trt
  
    # Pull out Root traits of interest and save these to the Sampled data frame
  SampledFit=merge(Fit2Average,sampledf,by=c("TRT","ML","Block"))

# Subset per treatment
  
  SampledFitComp=SampledFit%>%filter(TRT=="Inter")
  OTU_table_Comp=OTU_table[row.names(OTU_table)%in%SampledFitComp$Sample_ID,]
  
  SampledFitAlone=SampledFit%>%filter(TRT!="Inter")
  OTU_table_Alone=OTU_table[row.names(OTU_table)%in%SampledFitAlone$Sample_ID,]

    OTU_Comp=OTU_table_Comp
    Fit_Comp=SampledFitComp
  
    Fit_Alone=SampledFitAlone
    
    OTU_Alone=OTU_table_Alone

     # Remove NAS
    # Remove=which(Fit_Alone$LeafAv%in%NA)
    
    # Calculate fitness distances w euclidean distance 

    Fit.distComp=dist(Fit_Comp$RelativeFitAv)
    Fit.distAlone=dist(Fit_Alone[,"RelativeFitAv"])
    
    # Calculate size distances w euclidean distance 

    Leaf.distComp=dist(Fit_Comp$LeafAv)
    Leaf.distAlone=dist(Fit_Alone[,"LeafAv"])

    # Calculate Bray distance matrix for OTU table
    BrayComp=vegdist(OTU_Comp,method="bray")
    BrayAlone=vegdist(OTU_Alone,method="bray")

    # OTU Bray vs Fitness per treatment

    OTU_Fit_Comp_Par = mantel.partial(BrayComp, Fit.distComp, Leaf.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    OTU_Fit_Alone_Par = mantel.partial(BrayAlone, Fit.distAlone,Leaf.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)

MANTEL PARTIAL REGRESSION: between Bray Curtis and ROOTS onto Relative Fitnesses

#  Here we use the Family mean values of root traits---this would indicate evidence for 'phenotypic selection' 


RootFitAlphaMean<-RootFitAlpha%>%
                    group_by(TRT,ML,Block)%>% #Grouping factor
                    summarise("PC1_Avg"=mean(PC1,na.rm=T),"PC2_Avg"=mean(PC2,na.rm=T),"PC4_Avg"=mean(PC4,na.rm=T),"PC3_Avg"=mean(PC3,na.rm=T),"RelFit"=mean(RelativeFitness,na.rm=T))

  # Load matrix Bray distances of OTU abundance
  OTU_table=t(otu_table(physeq1)) # Write out OTU table
  

  # Pull out Root traits of interest and save these to the Sampled data frame
  SampledFit=merge(RootFitAlphaMean,sampledf,by=c("TRT","ML","Block"))

  # Subset per treatment
  
SampledFitComp=SampledFit%>%filter(TRT=="Inter")
OTU_table_Comp=OTU_table[row.names(OTU_table)%in%SampledFitComp$Sample_ID,]

SampledFitAlone=SampledFit%>%filter(TRT!="Inter")
OTU_table_Alone=OTU_table[row.names(OTU_table)%in%SampledFitAlone$Sample_ID,]

    OTU_Comp=OTU_table_Comp
    Fit_Comp=SampledFitComp
  
    OTU_Alone=OTU_table_Alone
    Fit_Alone=SampledFitAlone
    
    
    # Calculate fitness distances w euclidean distance 

    Fit.distComp=dist(Fit_Comp$RelFit)
    Fit.distAlone=dist(Fit_Alone$RelFit)
    
    # Calculate root distances w euclidean distance 

    PC1.distComp=dist(Fit_Comp$PC1_Avg)
    PC1.distAlone=dist(Fit_Alone$PC1_Avg)
    PC2.distComp=dist(Fit_Comp$PC2_Avg)
    PC2.distAlone=dist(Fit_Alone$PC2_Avg)
    PC3.distComp=dist(Fit_Comp$PC3_Avg)
    PC3.distAlone=dist(Fit_Alone$PC3_Avg)
    PC4.distComp=dist(Fit_Comp$PC4_Avg)
    PC4.distAlone=dist(Fit_Alone$PC4_Avg)
    
    
    # Calculate Bray distance matrix for OTU table
    BrayComp=vegdist(OTU_Comp,method="bray")
    BrayAlone=vegdist(OTU_Alone,method="bray")



# Run partial mantel test and control for ROOT traits
    

    # OTU Bray vs Fitness per treatment

    # Partial regression with root architecture
    OTU_FitPC2_Comp_Par = mantel.partial(BrayComp, Fit.distComp, PC2.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    OTU_FitPC2_Alone_Par = mantel.partial(BrayAlone, Fit.distAlone,PC2.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)
    
        # Partial regression with root SIZE

    OTU_FitPC3_Comp_Par = mantel.partial(BrayComp, Fit.distComp, PC3.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    OTU_FitPC3_Alone_Par = mantel.partial(BrayAlone, Fit.distAlone,PC3.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    
            # Partial regression with root morphology
    OTU_FitPC4_Comp_Par = mantel.partial(BrayComp, Fit.distComp, PC4.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    OTU_FitPC4_Alone_Par = mantel.partial(BrayAlone, Fit.distAlone,PC4.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    
          # Partial regression with root topology
    OTU_FitPC1_Comp_Par = mantel.partial(BrayComp, Fit.distComp, PC1.distComp, method = "spearman", permutations = 9999, na.rm = TRUE)
    
    OTU_FitPC1_Alone_Par = mantel.partial(BrayAlone, Fit.distAlone,PC1.distAlone, method = "spearman", permutations = 9999, na.rm = TRUE)